diff options
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/src/writer.c b/src/writer.c index f75c23a0..2671ba7d 100644 --- a/src/writer.c +++ b/src/writer.c @@ -89,24 +89,25 @@ static const SepRule rules[] = { }; struct SerdWriterImpl { - SerdSyntax syntax; - SerdStyle style; - SerdEnv* env; - SerdNode* root_node; - SerdURI root_uri; - SerdURI base_uri; - SerdStack anon_stack; - SerdByteSink byte_sink; - SerdErrorSink error_sink; - void* error_handle; - WriteContext context; - SerdNode* list_subj; - unsigned list_depth; - unsigned indent; - uint8_t* bprefix; - size_t bprefix_len; - Sep last_sep; - bool empty; + SerdSinkInterface iface; + SerdSyntax syntax; + SerdStyle style; + SerdEnv* env; + SerdNode* root_node; + SerdURI root_uri; + SerdURI base_uri; + SerdStack anon_stack; + SerdByteSink byte_sink; + SerdErrorSink error_sink; + void* error_handle; + WriteContext context; + SerdNode* list_subj; + unsigned list_depth; + unsigned indent; + uint8_t* bprefix; + size_t bprefix_len; + Sep last_sep; + bool empty; }; typedef enum { @@ -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,8 +699,7 @@ write_list_obj(SerdWriter* writer, return false; } -SERD_API -SerdStatus +static SerdStatus serd_writer_write_statement(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* graph, @@ -827,8 +832,7 @@ serd_writer_write_statement(SerdWriter* writer, return SERD_SUCCESS; } -SERD_API -SerdStatus +static SerdStatus serd_writer_end_anon(SerdWriter* writer, const SerdNode* node) { @@ -893,6 +897,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; } @@ -921,7 +932,6 @@ serd_writer_chop_blank_prefix(SerdWriter* writer, } } -SERD_API SerdStatus serd_writer_set_base_uri(SerdWriter* writer, const SerdNode* uri) @@ -961,7 +971,6 @@ serd_writer_set_root_uri(SerdWriter* writer, return SERD_SUCCESS; } -SERD_API SerdStatus serd_writer_set_prefix(SerdWriter* writer, const SerdNode* name, @@ -998,6 +1007,13 @@ serd_writer_free(SerdWriter* writer) } SERD_API +const SerdSinkInterface* +serd_writer_get_sink_interface(SerdWriter* writer) +{ + return &writer->iface; +} + +SERD_API SerdEnv* serd_writer_get_env(SerdWriter* writer) { |