2.8 Reader — Serd 0.32.10 documentation

# 2.8 Reader

typedef struct SerdReaderImpl SerdReader

  Streaming parser that reads a text stream and writes to a statement sink.

void serd_reader_add_blank_prefix(SerdReader *reader, const uint8_t *prefix)

  Set a prefix to be added to all blank node identifiers.

  This is useful when multiple files are to be parsed into the same output (a model or a file). Since Serd preserves blank node IDs, this could cause conflicts where two non-equivalent blank nodes are merged, resulting in corrupt data. By setting a unique blank node prefix for each parsed file, this can be avoided, while preserving blank node names.

SerdStatus serd_reader_end_stream(SerdReader *reader)

  Finish an incremental read from a file handle.

void serd_reader_free(SerdReader *reader)

  Free `reader`.

void *serd_reader_get_handle(const SerdReader *reader)

  Return the `handle` passed to `serd_reader_new()`.

SerdReader *serd_reader_new(SerdSyntax syntax, void *handle, void (*free_handle)(void*), SerdBaseSink base_sink, SerdPrefixSink prefix_sink, SerdStatementSink statement_sink, SerdEndSink end_sink)

  Create a new RDF reader.

SerdStatus serd_reader_read_chunk(SerdReader *reader)

  Read a single “chunk” of data during an incremental read.

  This function will read a single top level description, and return. This may be a directive, statement, or several statements; essentially it reads until a ‘.’ is encountered. This is particularly useful for reading directly from a pipe or socket.

SerdStatus serd_reader_read_file(SerdReader *reader, const uint8_t *uri)

  Read a file at a given `uri`.

SerdStatus serd_reader_read_file_handle(SerdReader *reader, FILE *file, const uint8_t *name)

  Read `file`.

SerdStatus serd_reader_read_source(SerdReader *reader, SerdSource source, SerdStreamErrorFunc error, void *stream, const uint8_t *name, size_t page_size)

  Read a user-specified byte source.

SerdStatus serd_reader_read_string(SerdReader *reader, const uint8_t *utf8)

  Read `utf8`.

void serd_reader_set_default_graph(SerdReader *reader, const SerdNode *graph)

  Set the URI of the default graph.

  If this is set, the reader will emit quads with the graph set to the given node for any statements that are not in a named graph (which is currently all of them since Serd currently does not support any graph syntaxes).

void serd_reader_set_error_sink(SerdReader *reader, SerdErrorSink error_sink, void *error_handle)

  Set a function to be called when errors occur during reading.

  The `error_sink` will be called with `handle` as its first argument. If no error function is set, errors are printed to stderr in GCC style.

void serd_reader_set_strict(SerdReader *reader, bool strict)

  Enable or disable strict parsing.

  The reader is non-strict (lax) by default, which will tolerate URIs with invalid characters. Setting strict will fail when parsing such files. An error is printed for invalid input in either case.

SerdStatus serd_reader_skip_until_byte(SerdReader *reader, uint8_t byte)

  Skip over bytes in the input until a specific byte is encountered.

  Typically used for recovering from errors in a line-based syntax by skipping ahead to the next newline.

  Returns:

    `SerdStatus.SERD_SUCCESS` if the given byte was reached, or `SerdStatus.SERD_FAILURE` if the end of input is reached.

SerdStatus serd_reader_start_source_stream(SerdReader *reader, SerdSource read_func, SerdStreamErrorFunc error_func, void *stream, const uint8_t *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).

SerdStatus serd_reader_start_stream(SerdReader *reader, FILE *file, const uint8_t *name, bool bulk)

  Start an incremental read from a file handle.

  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.