From 7026fb72f85e349eea64a62bd924358c608520cc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 30 May 2020 21:32:37 +0200 Subject: Replace multiple stream callbacks with SerdEvent This makes plumbing easier since everything goes through the same "stream" and only one callback is required to handling everything. It's also more easily extensible in case more event types need to be added in the future. --- src/writer.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/writer.c') diff --git a/src/writer.c b/src/writer.c index 2686cc8a..29d9e902 100644 --- a/src/writer.c +++ b/src/writer.c @@ -996,6 +996,27 @@ serd_writer_end_anon(SerdWriter* writer, const SerdNode* node) return st; } +static SerdStatus +serd_writer_on_event(SerdWriter* writer, const SerdEvent* event) +{ + switch (event->type) { + case SERD_BASE: + return serd_writer_set_base_uri(writer, event->base.uri); + case SERD_PREFIX: + return serd_writer_set_prefix(writer, + event->prefix.name, + event->prefix.uri); + case SERD_STATEMENT: + return serd_writer_write_statement(writer, + event->statement.flags, + event->statement.statement); + case SERD_END: + return serd_writer_end_anon(writer, event->end.node); + } + + return SERD_SUCCESS; +} + SerdStatus serd_writer_finish(SerdWriter* writer) { @@ -1037,11 +1058,8 @@ serd_writer_new(SerdWorld* world, writer->context = context; writer->empty = true; - 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; + writer->iface.handle = writer; + writer->iface.on_event = (SerdEventFunc)serd_writer_on_event; return writer; } -- cgit v1.2.1