Byte Source¶
-
typedef struct SerdByteSourceImpl
SerdByteSource¶ A source for bytes that provides text input.
-
typedef int (*
SerdStreamErrorFunc)(void *stream)¶ Function to detect I/O stream errors.
Identical semantics to
ferror.- Returns
Non-zero if
streamhas encountered an error.
-
typedef size_t (*
SerdReadFunc)(void *buf, size_t size, size_t nmemb, void *stream)¶ Source function for raw string input.
Identical semantics to
fread, but may set errno for more informative error reporting than supported by SerdStreamErrorFunc.- Parameters
buf – Output buffer.
size – Size of a single element of data in bytes (always 1).
nmemb – Number of elements to read.
stream – Stream to read from (FILE* for fread).
- Returns
Number of elements (bytes) read, which is short on error.
-
SerdByteSource *
serd_byte_source_new_string(const char *string, const SerdNode *name)¶ Create a new byte source that reads from a string.
- Parameters
string – Null-terminated UTF-8 string to read from.
name – Optional name of stream for error messages (string or URI).
-
SerdByteSource *
serd_byte_source_new_filename(const char *path, size_t block_size)¶ Create a new byte source that reads from a file.
An arbitrary
FILE*can be used viaserd_byte_source_new_function()as well, this is just a convenience function that opens the file properly, sets flags for optimized I/O if possible, and automatically sets the name of the source to the file path.- Parameters
path – Path of file to open and read from.
block_size – Number of bytes to read per call.
-
SerdByteSource *
serd_byte_source_new_function(SerdReadFunc read_func, SerdStreamErrorFunc error_func, void *stream, const SerdNode *name, size_t block_size)¶ Create a new byte source that reads from a user-specified function.
The
streamwill be passed to theread_func, which is compatible with the standard Cfreadifstreamis aFILE*. Note that the serd Reader only ever reads individual bytes at a time, that is, thesizeparameter will always be 1 (butnmembmay be higher).- Parameters
read_func – Function called with bytes to consume.
error_func – Stream error function with
ferrorsemantics.stream – Context parameter passed to
read_funcanderror_func.name – Optional name of stream for error messages (string or URI).
block_size – Number of bytes to read per call.
-
void
serd_byte_source_free(SerdByteSource *source)¶ Free
source