aboutsummaryrefslogtreecommitdiffstats
path: root/serd/serd.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-04-14 10:51:46 +0200
committerDavid Robillard <d@drobilla.net>2017-04-14 20:58:03 +0200
commit1ae793464e0cfb71dedc9807d97132fdc6145005 (patch)
tree5027e4f929ccfb1a3abd488d5f3498f0cc3fe850 /serd/serd.h
parenta5005d0e75bc2ea9f453d5e35f611f078f200b8b (diff)
downloadserd-1ae793464e0cfb71dedc9807d97132fdc6145005.tar.gz
serd-1ae793464e0cfb71dedc9807d97132fdc6145005.tar.bz2
serd-1ae793464e0cfb71dedc9807d97132fdc6145005.zip
Factor out file reading from reader
Diffstat (limited to 'serd/serd.h')
-rw-r--r--serd/serd.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index e7f6ec3b..0ba3dffd 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -377,6 +377,32 @@ void
serd_uri_resolve(const SerdURI* uri, const SerdURI* base, SerdURI* out);
/**
+ Function to detect I/O stream errors.
+
+ Identical semantics to `ferror`.
+
+ @return Non-zero if `stream` has encountered an error.
+*/
+typedef int (*SerdStreamErrorFunc)(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.
+
+ @param buf Output buffer.
+ @param size Size of a single element of data in bytes (always 1).
+ @param nmemb Number of elements to read.
+ @param stream Stream to read from (FILE* for fread).
+ @return Number of elements (bytes) read.
+*/
+typedef size_t (*SerdSource)(void* buf,
+ size_t size,
+ size_t nmemb,
+ void* stream);
+
+/**
Sink function for raw string output.
*/
typedef size_t (*SerdSink)(const void* buf, size_t len, void* stream);
@@ -799,6 +825,21 @@ serd_reader_start_stream(SerdReader* me,
bool bulk);
/**
+ Start an incremental read from a user-specified source.
+
+ Iff `bulk` is true, `source` will be read a page at a time. Otherwise,
+ `source` is guaranteed to only be called for single bytes.
+*/
+SERD_API
+SerdStatus
+serd_reader_start_source_stream(SerdReader* me,
+ SerdSource read_func,
+ SerdStreamErrorFunc error_func,
+ void* stream,
+ const uint8_t* name,
+ bool bulk);
+
+/**
Read a single "chunk" of data during an incremental read.
This function will read a single top level description, and return. This
@@ -827,6 +868,17 @@ serd_reader_read_file_handle(SerdReader* reader,
const uint8_t* name);
/**
+ Read a user-specified byte source.
+*/
+SERD_API
+SerdStatus
+serd_reader_read_source(SerdReader* reader,
+ SerdSource source,
+ SerdStreamErrorFunc error,
+ void* stream,
+ const uint8_t* name);
+
+/**
Read `utf8`.
*/
SERD_API