Writer¶
-
struct SerdWriterImpl
SerdWriter¶ Streaming serialiser that writes a text stream as statements are pushed.
-
SerdWriter *
serd_writer_new(SerdSyntax syntax, SerdStyle style, SerdEnv *env, const SerdURI *base_uri, SerdSink ssink, void *stream)¶ Create a new RDF writer.
-
void
serd_writer_free(SerdWriter *writer)¶ Free
writer
-
SerdEnv *
serd_writer_get_env(SerdWriter *writer)¶ Return the env used by
writer
-
size_t
serd_file_sink(const void *buf, size_t len, void *stream)¶ A convenience sink function for writing to a FILE*.
This function can be used as a SerdSink when writing to a FILE*. The
streamparameter must be a FILE* opened for writing.
-
size_t
serd_chunk_sink(const void *buf, size_t len, void *stream)¶ A convenience sink function for writing to a string.
This function can be used as a SerdSink to write to a :c:struct:`SerdChunk` which is resized as necessary with realloc(). The
streamparameter must point to an initialized :c:struct:`SerdChunk`. When the write is finished, the string should be retrieved withserd_chunk_sink_finish().
-
uint8_t *
serd_chunk_sink_finish(SerdChunk *stream)¶ Finish a serialisation to a chunk with
serd_chunk_sink().The returned string is the result of the serialisation, which is null terminated (by this function) and owned by the caller.
-
void
serd_writer_set_error_sink(SerdWriter *writer, SerdErrorSink error_sink, void *error_handle)¶ Set a function to be called when errors occur during writing.
The
error_sinkwill be called withhandleas its first argument. If no error function is set, errors are printed to stderr.
-
void
serd_writer_chop_blank_prefix(SerdWriter *writer, const uint8_t *prefix)¶ Set a prefix to be removed from matching blank node identifiers.
This is the counterpart to
serd_reader_add_blank_prefix()which can be used to “undo” added prefixes.
-
SerdStatus
serd_writer_set_base_uri(SerdWriter *writer, const SerdNode *uri)¶ Set the current output base URI, and emit a directive if applicable.
Note this function can be safely casted to SerdBaseSink.
-
SerdStatus
serd_writer_set_root_uri(SerdWriter *writer, const SerdNode *uri)¶ Set the current root URI.
The root URI should be a prefix of the base URI. The path of the root URI is the highest path any relative up-reference can refer to. For example, with root file:///foo/root and base file:///foo/root/base, file:///foo/root will be written as <../>, but file:///foo will be written non-relatively as file:///foo. If the root is not explicitly set, it defaults to the base URI, so no up-references will be created at all.
-
SerdStatus
serd_writer_set_prefix(SerdWriter *writer, const SerdNode *name, const SerdNode *uri)¶ Set a namespace prefix (and emit directive if applicable).
Note this function can be safely casted to SerdPrefixSink.
-
SerdStatus
serd_writer_write_statement(SerdWriter *writer, SerdStatementFlags flags, const SerdNode *graph, const SerdNode *subject, const SerdNode *predicate, const SerdNode *object, const SerdNode *datatype, const SerdNode *lang)¶ Write a statement.
Note this function can be safely casted to SerdStatementSink.
-
SerdStatus
serd_writer_end_anon(SerdWriter *writer, const SerdNode *node)¶ Mark the end of an anonymous node’s description.
Note this function can be safely casted to SerdEndSink.
-
SerdStatus
serd_writer_finish(SerdWriter *writer)¶ Finish a write.
This flushes any pending output, for example terminating punctuation, so that the output is a complete document.