diff options
author | David Robillard <d@drobilla.net> | 2021-03-01 19:38:01 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-07 15:32:24 -0500 |
commit | b085fe7aa38e5e2caf82b1fec6b7e6094779dd5a (patch) | |
tree | d6058aef1c4323ad7039e8e16076cc52f1e7514e /src/writer.c | |
parent | 58890c798fbd87a2080c2fa8cc206a2631c3e558 (diff) | |
download | serd-b085fe7aa38e5e2caf82b1fec6b7e6094779dd5a.tar.gz serd-b085fe7aa38e5e2caf82b1fec6b7e6094779dd5a.tar.bz2 serd-b085fe7aa38e5e2caf82b1fec6b7e6094779dd5a.zip |
Add SerdSink interface and hide implementations
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/writer.c b/src/writer.c index e23058f0..2b2d5ed8 100644 --- a/src/writer.c +++ b/src/writer.c @@ -18,6 +18,7 @@ #include "env.h" #include "node.h" #include "serd_internal.h" +#include "sink.h" #include "stack.h" #include "string_utils.h" #include "uri_utils.h" @@ -92,6 +93,7 @@ static const SepRule rules[] = {{NULL, 0, 0, 0, 0}, {"\n", 1, 0, 1, 0}}; struct SerdWriterImpl { + SerdSink iface; SerdSyntax syntax; SerdWriterFlags flags; SerdEnv* env; @@ -113,6 +115,11 @@ struct SerdWriterImpl { typedef enum { WRITE_STRING, WRITE_LONG_STRING } TextContext; +static SerdStatus +serd_writer_set_prefix(SerdWriter* writer, + const SerdNode* name, + const SerdNode* uri); + static bool write_node(SerdWriter* writer, const SerdNode* node, @@ -785,7 +792,7 @@ write_list_obj(SerdWriter* writer, return false; } -SerdStatus +static SerdStatus serd_writer_write_statement(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* graph, @@ -915,7 +922,7 @@ serd_writer_write_statement(SerdWriter* writer, return SERD_SUCCESS; } -SerdStatus +static SerdStatus serd_writer_end_anon(SerdWriter* writer, const SerdNode* node) { if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) { @@ -976,6 +983,12 @@ serd_writer_new(SerdSyntax syntax, writer->byte_sink = serd_byte_sink_new( ssink, stream, (flags & SERD_WRITE_BULK) ? SERD_PAGE_SIZE : 1); + writer->iface.handle = writer; + writer->iface.base = (SerdBaseFunc)serd_writer_set_base_uri; + writer->iface.prefix = (SerdPrefixFunc)serd_writer_set_prefix; + writer->iface.statement = (SerdStatementFunc)serd_writer_write_statement; + writer->iface.end = (SerdEndFunc)serd_writer_end_anon; + return writer; } @@ -1083,6 +1096,12 @@ serd_writer_free(SerdWriter* writer) free(writer); } +const SerdSink* +serd_writer_sink(SerdWriter* writer) +{ + return &writer->iface; +} + SerdEnv* serd_writer_env(SerdWriter* writer) { |