From 480bcd2744779686916763e9a5a876afd43643b4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 8 Jul 2018 18:46:38 +0200 Subject: Expose SerdByteSink in public API --- include/serd/serd.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'include/serd') diff --git a/include/serd/serd.h b/include/serd/serd.h index 9a414b11..66f22cbd 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -258,6 +258,9 @@ serd_strlen(const char* SERD_NONNULL str, SerdNodeFlags* SERD_NULLABLE flags); @{ */ +/// A sink for bytes that receives text output +typedef struct SerdByteSinkImpl SerdByteSink; + /** Function to detect I/O stream errors. @@ -301,6 +304,41 @@ typedef size_t (*SerdWriteFunc)(const void* SERD_NONNULL buf, size_t nmemb, void* SERD_NONNULL stream); +/** + Create a new byte sink. + + @param write_func Function called with bytes to consume. + @param stream Context parameter passed to `sink`. + @param block_size Number of bytes to write per call. +*/ +SERD_API +SerdByteSink* SERD_ALLOCATED +serd_byte_sink_new(SerdWriteFunc SERD_NONNULL write_func, + void* SERD_NULLABLE stream, + size_t block_size); + +/** + Write to `sink`. + + Compatible with SerdWriteFunc. +*/ +SERD_API +size_t +serd_byte_sink_write(const void* SERD_NONNULL buf, + size_t size, + size_t nmemb, + SerdByteSink* SERD_NONNULL sink); + +/// Flush any pending output in `sink` to the underlying write function +SERD_API +void +serd_byte_sink_flush(SerdByteSink* SERD_NONNULL sink); + +/// Free `sink` +SERD_API +void +serd_byte_sink_free(SerdByteSink* SERD_NULLABLE sink); + /** @} @defgroup serd_syntax Syntax Utilities -- cgit v1.2.1