aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-05-30 21:32:37 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:59 +0100
commit7026fb72f85e349eea64a62bd924358c608520cc (patch)
tree857cef38b39ceb3687216e91904b5edc7bf48a0c /src/writer.c
parent797eb91498ea83003922b70aa943925b4fb81bb5 (diff)
downloadserd-7026fb72f85e349eea64a62bd924358c608520cc.tar.gz
serd-7026fb72f85e349eea64a62bd924358c608520cc.tar.bz2
serd-7026fb72f85e349eea64a62bd924358c608520cc.zip
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.
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c28
1 files changed, 23 insertions, 5 deletions
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;
}