aboutsummaryrefslogtreecommitdiffstats
path: root/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-15 23:21:34 -0400
committerDavid Robillard <d@drobilla.net>2019-04-13 19:15:32 +0200
commita549e968cd3f840dc98b2e199c5f52e9f5a5780c (patch)
tree47b9f12595dc62af719a58ccf2e83d20743b0c95 /serd
parent499e27a6849cb98235bf9425f1fdb96c8da2c8c5 (diff)
downloadserd-a549e968cd3f840dc98b2e199c5f52e9f5a5780c.tar.gz
serd-a549e968cd3f840dc98b2e199c5f52e9f5a5780c.tar.bz2
serd-a549e968cd3f840dc98b2e199c5f52e9f5a5780c.zip
Use SerdBuffer for mutable buffers
This avoids const violations from abusing SerdChunk as a mutable buffer for string sinks.
Diffstat (limited to 'serd')
-rw-r--r--serd/serd.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/serd/serd.h b/serd/serd.h
index b88cb8f8..a24f3a36 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -230,6 +230,14 @@ typedef struct {
} SerdChunk;
/**
+ A mutable buffer in memory.
+*/
+typedef struct {
+ void* buf; /**< Buffer */
+ size_t len; /**< Size of buffer in bytes */
+} SerdBuffer;
+
+/**
An error description.
*/
typedef struct {
@@ -971,24 +979,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.