From 9b3d8263604ba11ae008c8651a1fe2063296d6b1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 15 Mar 2016 23:21:34 -0400 Subject: Use SerdBuffer for mutable buffers This avoids const violations from abusing SerdChunk as a mutable buffer for string sinks. --- serd/serd.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'serd/serd.h') diff --git a/serd/serd.h b/serd/serd.h index b3056239..49ee3c3a 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -230,6 +230,14 @@ typedef struct { size_t len; /**< Length of chunk in bytes */ } SerdChunk; +/** + A mutable buffer in memory. +*/ +typedef struct { + void* buf; /**< Buffer */ + size_t len; /**< Size of buffer in bytes */ +} SerdBuffer; + /** An error description. */ @@ -955,24 +963,24 @@ serd_file_sink(const void* buf, size_t len, void* stream); /** A convenience sink function for writing to a string. - This function can be used as a SerdSink to write to a SerdChunk which is + This function can be used as a SerdSink to write to a SerdBuffer which is resized as necessary with realloc(). The `stream` parameter must point to - an initialized SerdChunk. When the write is finished, the string should be - retrieved with serd_chunk_sink_finish(). + an initialized SerdBuffer. When the write is finished, the string should be + retrieved with serd_buffer_sink_finish(). */ SERD_API size_t -serd_chunk_sink(const void* buf, size_t len, void* stream); +serd_buffer_sink(const void* buf, size_t len, void* stream); /** - Finish a serialisation to a chunk with serd_chunk_sink(). + Finish a serialisation to a chunk with serd_buffer_sink(). The returned string is the result of the serialisation, which is NULL terminated (by this function) and owned by the caller. */ SERD_API uint8_t* -serd_chunk_sink_finish(SerdChunk* stream); +serd_buffer_sink_finish(SerdBuffer* stream); /** Set a function to be called when errors occur during writing. -- cgit v1.2.1