aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-06-28 19:46:47 +0200
committerDavid Robillard <d@drobilla.net>2022-01-13 23:04:17 -0500
commitcae15d15c847faba203e40e2a327b23a1ebffb48 (patch)
tree17d1e637673ef45c3afdc3c43b67f0b023b8d851 /src/writer.c
parent900d360027d570da085d495becde1ad50f050048 (diff)
downloadserd-cae15d15c847faba203e40e2a327b23a1ebffb48.tar.gz
serd-cae15d15c847faba203e40e2a327b23a1ebffb48.tar.bz2
serd-cae15d15c847faba203e40e2a327b23a1ebffb48.zip
Make Writer always write to a ByteSink
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/writer.c b/src/writer.c
index 3e0faa1e..3606fe44 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -14,6 +14,7 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "byte_sink.h"
#include "env.h"
#include "node.h"
#include "serd_internal.h"
@@ -130,8 +131,7 @@ struct SerdWriterImpl {
SerdURIView root_uri;
WriteContext* anon_stack;
size_t anon_stack_size;
- SerdWriteFunc write_func;
- void* stream;
+ SerdByteSink* byte_sink;
WriteContext context;
char* bprefix;
size_t bprefix_len;
@@ -225,7 +225,7 @@ ctx(SerdWriter* writer, const SerdField field)
SERD_WARN_UNUSED_RESULT static size_t
sink(const void* buf, size_t len, SerdWriter* writer)
{
- const size_t written = writer->write_func(buf, 1, len, writer->stream);
+ const size_t written = serd_byte_sink_write(buf, len, writer->byte_sink);
if (written != len) {
if (errno) {
char message[1024] = {0};
@@ -1134,22 +1134,20 @@ serd_writer_new(SerdWorld* world,
SerdSyntax syntax,
SerdWriterFlags flags,
SerdEnv* env,
- SerdWriteFunc write_func,
- void* stream)
+ SerdByteSink* byte_sink)
{
const WriteContext context = WRITE_CONTEXT_NULL;
SerdWriter* writer = (SerdWriter*)calloc(1, sizeof(SerdWriter));
- writer->world = world;
- writer->syntax = syntax;
- writer->flags = flags;
- writer->env = env;
- writer->root_node = NULL;
- writer->root_uri = SERD_URI_NULL;
- writer->write_func = write_func;
- writer->stream = stream;
- writer->context = context;
- writer->empty = true;
+ writer->world = world;
+ writer->syntax = syntax;
+ writer->flags = flags;
+ writer->env = env;
+ writer->root_node = NULL;
+ writer->root_uri = SERD_URI_NULL;
+ writer->byte_sink = byte_sink;
+ writer->context = context;
+ writer->empty = true;
writer->anon_stack =
(WriteContext*)calloc(anon_stack_capacity, sizeof(WriteContext));