aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd/serd.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-01-13 14:31:00 +0100
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit82f8f804773b10c42b17a30872a59ed76b062794 (patch)
tree73b6ebdde09b41126f37f3f4fc7fbe44b07ec3fb /include/serd/serd.h
parent84bab08585dec858807a6130bd2d71f304b889f0 (diff)
downloadserd-82f8f804773b10c42b17a30872a59ed76b062794.tar.gz
serd-82f8f804773b10c42b17a30872a59ed76b062794.tar.bz2
serd-82f8f804773b10c42b17a30872a59ed76b062794.zip
Add SerdBuffer type for mutable buffers
This avoids const violations from abusing SerdChunk as a mutable buffer for string sinks.
Diffstat (limited to 'include/serd/serd.h')
-rw-r--r--include/serd/serd.h24
1 files changed, 15 insertions, 9 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 3b47ce5c..80d6b230 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -82,6 +82,12 @@ typedef struct {
size_t len; ///< Length of chunk in bytes
} SerdChunk;
+/// A mutable buffer in memory
+typedef struct {
+ void* SERD_NULLABLE buf; ///< Buffer
+ size_t len; ///< Size of buffer in bytes
+} SerdBuffer;
+
/**
Free memory allocated by Serd.
@@ -851,24 +857,24 @@ serd_file_sink(const void* SERD_NONNULL buf,
/**
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* SERD_NONNULL buf,
- size_t len,
- void* SERD_NONNULL stream);
+serd_buffer_sink(const void* SERD_NONNULL buf,
+ size_t len,
+ void* SERD_NONNULL 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 char* SERD_NULLABLE
-serd_chunk_sink_finish(SerdChunk* SERD_NONNULL stream);
+SERD_API char* SERD_NONNULL
+serd_buffer_sink_finish(SerdBuffer* SERD_NONNULL stream);
/**
Set a function to be called when errors occur during writing.