diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/SocketWriter.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/SocketWriter.cpp b/src/SocketWriter.cpp index 23c28394..3ef9f2a2 100644 --- a/src/SocketWriter.cpp +++ b/src/SocketWriter.cpp @@ -25,6 +25,8 @@ # define MSG_NOSIGNAL 0 #endif +#define USTR(s) ((const uint8_t*)(s)) + namespace Ingen { static size_t @@ -38,6 +40,14 @@ socket_sink(const void* buf, size_t len, void* stream) return ret; } +static SerdStatus +write_prefix(void* handle, const SerdNode* name, const SerdNode* uri) +{ + SocketWriter* writer = (SocketWriter*)handle; + serd_writer_set_prefix(writer->writer(), name, uri); + return SERD_SUCCESS; +} + SocketWriter::SocketWriter(URIMap& map, URIs& uris, const Raul::URI& uri, @@ -53,7 +63,20 @@ SocketWriter::SocketWriter(URIMap& map, serd_uri_parse(_base.buf, &_base_uri); - _env = serd_env_new(&_base); + // Set up serialisation environment + _env = serd_env_new(&_base); + serd_env_set_prefix_from_strings(_env, USTR("atom"), USTR("http://lv2plug.in/ns/ext/atom#")); + serd_env_set_prefix_from_strings(_env, USTR("patch"), USTR("http://lv2plug.in/ns/ext/patch#")); + serd_env_set_prefix_from_strings(_env, USTR("doap"), USTR("http://usefulinc.com/ns/doap#")); + serd_env_set_prefix_from_strings(_env, USTR("ingen"), USTR(INGEN_NS)); + serd_env_set_prefix_from_strings(_env, USTR("lv2"), USTR("http://lv2plug.in/ns/lv2core#")); + serd_env_set_prefix_from_strings(_env, USTR("midi"), USTR("http://lv2plug.in/ns/ext/midi#")); + serd_env_set_prefix_from_strings(_env, USTR("owl"), USTR("http://www.w3.org/2002/07/owl#")); + serd_env_set_prefix_from_strings(_env, USTR("rdf"), USTR("http://www.w3.org/1999/02/22-rdf-syntax-ns#")); + serd_env_set_prefix_from_strings(_env, USTR("rdfs"), USTR("http://www.w3.org/2000/01/rdf-schema#")); + serd_env_set_prefix_from_strings(_env, USTR("xsd"), USTR("http://www.w3.org/2001/XMLSchema#")); + + // Make a Turtle writer that writes directly to the socket _writer = serd_writer_new( SERD_TURTLE, (SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED), @@ -62,6 +85,10 @@ SocketWriter::SocketWriter(URIMap& map, socket_sink, this); + // Write namespace prefixes to reduce traffic + serd_env_foreach(_env, write_prefix, this); + + // Configure sratom to write directly to the writer (and thus the socket) sratom_set_sink(_sratom, (const char*)_base.buf, (SerdStatementSink)serd_writer_write_statement, |