From aebfe13a070ee542929e0ec19b4b2e9221dc1582 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 10 May 2018 19:29:22 +0200 Subject: Add SerdSink interface and hide individual function implementations --- src/writer.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/writer.c') diff --git a/src/writer.c b/src/writer.c index 8331f5ee..11ef0692 100644 --- a/src/writer.c +++ b/src/writer.c @@ -89,6 +89,7 @@ static const SepRule rules[] = { }; struct SerdWriterImpl { + SerdSink iface; SerdSyntax syntax; SerdStyle style; SerdEnv* env; @@ -114,6 +115,11 @@ typedef enum { 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, @@ -693,7 +699,7 @@ write_list_obj(SerdWriter* writer, return false; } -SerdStatus +static SerdStatus serd_writer_write_statement(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* graph, @@ -826,7 +832,7 @@ serd_writer_write_statement(SerdWriter* writer, return SERD_SUCCESS; } -SerdStatus +static SerdStatus serd_writer_end_anon(SerdWriter* writer, const SerdNode* node) { @@ -889,6 +895,13 @@ serd_writer_new(SerdSyntax syntax, writer->empty = true; writer->byte_sink = serd_byte_sink_new( ssink, stream, (style & SERD_STYLE_BULK) ? SERD_PAGE_SIZE : 1); + + writer->iface.handle = writer; + writer->iface.base = (SerdBaseSink)serd_writer_set_base_uri; + writer->iface.prefix = (SerdPrefixSink)serd_writer_set_prefix; + writer->iface.statement = (SerdStatementSink)serd_writer_write_statement; + writer->iface.end = (SerdEndSink)serd_writer_end_anon; + return writer; } @@ -987,6 +1000,12 @@ serd_writer_free(SerdWriter* writer) free(writer); } +SerdSink* +serd_writer_get_sink(SerdWriter* writer) +{ + return &writer->iface; +} + SerdEnv* serd_writer_get_env(SerdWriter* writer) { -- cgit v1.2.1