5.12.3 Buffer¶
The SerdBuffer
type represents a writable area of memory with a known size.
An implementation of SerdWriteFunc
, SerdErrorFunc
, and SerdCloseFunc
are provided which allow output to be written to a buffer in memory instead of to a file as with fwrite
, ferror
, and fclose
.
-
struct SerdBuffer¶
A mutable buffer in memory.
-
void *buf¶
Buffer.
-
size_t len¶
Size of buffer in bytes.
-
void *buf¶
-
struct SerdDynamicBuffer¶
A dynamically resizable mutable buffer in memory.
-
SerdAllocator *allocator¶
Allocator for buf.
-
void *buf¶
Buffer.
-
size_t len¶
Size of buffer in bytes.
-
SerdAllocator *allocator¶
-
size_t serd_buffer_write(const void *buf, size_t size, size_t nmemb, void *stream)¶
A function for writing to a buffer, resizing it if necessary.
This function can be used as a
SerdWriteFunc
to write to aSerdDynamicBuffer
which is reallocated as necessary. Thestream
parameter must point to an initializedSerdDynamicBuffer
.Note that when writing a string, the string in the buffer will not be null-terminated until
serd_buffer_close()
is called.
-
int serd_buffer_close(void *stream)¶
Close the buffer for writing.
This writes a terminating null byte, so the contents of the buffer are safe to read as a string after this call.