From 0e24282852a889894dfc3e3afa61766a4b8f4ddb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 10 Feb 2018 13:32:06 +0100 Subject: Simplify reader interface --- serd/serd.h | 54 ++++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 36 deletions(-) (limited to 'serd') diff --git a/serd/serd.h b/serd/serd.h index 27c20c11..40ae6c4d 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -854,34 +854,26 @@ serd_reader_read_file(SerdReader* reader, const char* uri); /** - Start an incremental read from a file handle. + Prepare to read from a stream. - Iff `bulk` is true, `file` will be read a page at a time. This is more - efficient, but uses a page of memory and means that an entire page of input - must be ready before any callbacks will fire. To react as soon as input - arrives, set `bulk` to false. + The `read_func` is guaranteed to only be called for `page_size` elements + with size 1 (i.e. `page_size` bytes). */ SERD_API SerdStatus -serd_reader_start_stream(SerdReader* reader, - FILE* file, - const char* name, - bool bulk); +serd_reader_start_stream(SerdReader* reader, + SerdSource read_func, + SerdStreamErrorFunc error_func, + void* stream, + const char* name, + size_t page_size); /** - Start an incremental read from a user-specified source. - - The `read_func` is guaranteed to only be called for `page_size` elements - with size 1 (i.e. `page_size` bytes). + Prepare to read from a string. */ SERD_API SerdStatus -serd_reader_start_source_stream(SerdReader* reader, - SerdSource read_func, - SerdStreamErrorFunc error_func, - void* stream, - const char* name, - size_t page_size); +serd_reader_start_string(SerdReader* reader, const char* utf8); /** Read a single "chunk" of data during an incremental read. @@ -896,32 +888,22 @@ SerdStatus serd_reader_read_chunk(SerdReader* reader); /** - Finish an incremental read from a file handle. -*/ -SERD_API -SerdStatus -serd_reader_end_stream(SerdReader* reader); + Read a complete document from the source. -/** - Read `file`. + This function will continue pulling from the source until a complete + document has been read. Note that this may block when used with streams, + for incremental reading use serd_reader_read_chunk(). */ SERD_API SerdStatus -serd_reader_read_file_handle(SerdReader* reader, - FILE* file, - const char* name); +serd_reader_read_document(SerdReader* reader); /** - Read a user-specified byte source. + Finish reading from the source. */ SERD_API SerdStatus -serd_reader_read_source(SerdReader* reader, - SerdSource source, - SerdStreamErrorFunc error, - void* stream, - const char* name, - size_t page_size); +serd_reader_end_stream(SerdReader* reader); /** Read `utf8`. -- cgit v1.2.1