---
name: "serd"
section: "3"
platform: "linux"
package: "libserd-doc"
version: "0.32.4-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/serd"
---

# serd(3)

A lightweight RDF syntax library

## NAME

serd - A lightweight RDF syntax library

## SYNOPSIS

### Data Structures

struct **SerdNode**\
 struct **SerdChunk**\
 struct **SerdError**\
 struct **SerdURI**\

### Typedefs

typedef struct SerdEnvImpl **SerdEnv**\
 typedef struct SerdReaderImpl **SerdReader**\
 typedef struct SerdWriterImpl **SerdWriter**\
 typedef uint32\_t **SerdStatementFlags**\
 typedef uint32\_t **SerdNodeFlags**\

### Enumerations

enum **SerdStatus** \
 enum **SerdSyntax** \
 enum **SerdStatementFlag** \
 enum **SerdType** \
 enum **SerdNodeFlag** \
 enum **SerdStyle** \

### Functions

void **serd\_free** (void \*ptr)\

### String Utilities

const uint8\_t \* **serd\_strerror** (**SerdStatus** status)\
 size\_t **serd\_strlen** (const uint8\_t \*str, size\_t \*n\_bytes, **SerdNodeFlags** \*flags)\
 double **serd\_strtod** (const char \*str, char \*\*endptr)\
 void \* **serd\_base64\_decode** (const uint8\_t \*str, size\_t len, size\_t \*size)\

### Byte Streams

typedef int(\* **SerdStreamErrorFunc**) (void \*stream)\
 typedef size\_t(\* **SerdSource**) (void \*buf, size\_t size, size\_t nmemb, void \*stream)\
 typedef size\_t(\* **SerdSink**) (const void \*buf, size\_t len, void \*stream)\

### URI

static const **SerdURI** **SERD\_URI\_NULL**\
 const uint8\_t \* **serd\_uri\_to\_path** (const uint8\_t \*uri)\
 uint8\_t \* **serd\_file\_uri\_parse** (const uint8\_t \*uri, uint8\_t \*\*hostname)\
 bool **serd\_uri\_string\_has\_scheme** (const uint8\_t \*utf8)\
 **SerdStatus** **serd\_uri\_parse** (const uint8\_t \*utf8, **SerdURI** \*out)\
 void **serd\_uri\_resolve** (const **SerdURI** \*r, const **SerdURI** \*base, **SerdURI** \*t)\
 size\_t **serd\_uri\_serialise** (const **SerdURI** \*uri, **SerdSink** sink, void \*stream)\
 size\_t **serd\_uri\_serialise\_relative** (const **SerdURI** \*uri, const **SerdURI** \*base, const **SerdURI** \*root, **SerdSink** sink, void \*stream)\

### Node

static const **SerdNode** **SERD\_NODE\_NULL** = { NULL, 0, 0, 0, **SERD\_NOTHING** }\
 **SerdNode** **serd\_node\_from\_string** (**SerdType** type, const uint8\_t \*str)\
 **SerdNode** **serd\_node\_from\_substring** (**SerdType** type, const uint8\_t \*str, size\_t len)\
 **SerdNode** **serd\_node\_copy** (const **SerdNode** \*node)\
 bool **serd\_node\_equals** (const **SerdNode** \*a, const **SerdNode** \*b)\
 **SerdNode** **serd\_node\_new\_uri\_from\_node** (const **SerdNode** \*uri\_node, const **SerdURI** \*base, **SerdURI** \*out)\
 **SerdNode** **serd\_node\_new\_uri\_from\_string** (const uint8\_t \*str, const **SerdURI** \*base, **SerdURI** \*out)\
 **SerdNode** **serd\_node\_new\_file\_uri** (const uint8\_t \*path, const uint8\_t \*hostname, **SerdURI** \*out, bool escape)\
 **SerdNode** **serd\_node\_new\_uri** (const **SerdURI** \*uri, const **SerdURI** \*base, **SerdURI** \*out)\
 **SerdNode** **serd\_node\_new\_relative\_uri** (const **SerdURI** \*uri, const **SerdURI** \*base, const **SerdURI** \*root, **SerdURI** \*out)\
 **SerdNode** **serd\_node\_new\_decimal** (double d, unsigned frac\_digits)\
 **SerdNode** **serd\_node\_new\_integer** (int64\_t i)\
 **SerdNode** **serd\_node\_new\_blob** (const void \*buf, size\_t size, bool wrap\_lines)\
 void **serd\_node\_free** (**SerdNode** \*node)\

### Event Handlers

typedef **SerdStatus**(\* **SerdErrorSink**) (void \*handle, const **SerdError** \*error)\
 typedef **SerdStatus**(\* **SerdBaseSink**) (void \*handle, const **SerdNode** \*uri)\
 typedef **SerdStatus**(\* **SerdPrefixSink**) (void \*handle, const **SerdNode** \*name, const **SerdNode** \*uri)\
 typedef **SerdStatus**(\* **SerdStatementSink**) (void \*handle, **SerdStatementFlags** flags, const **SerdNode** \*graph, const **SerdNode** \*subject, const **SerdNode** \*predicate, const **SerdNode** \*object, const **SerdNode** \*object\_datatype, const **SerdNode** \*object\_lang)\
 typedef **SerdStatus**(\* **SerdEndSink**) (void \*handle, const **SerdNode** \*node)\

### Environment

**SerdEnv** \* **serd\_env\_new** (const **SerdNode** \*base\_uri)\
 void **serd\_env\_free** (**SerdEnv** \*env)\
 const **SerdNode** \* **serd\_env\_get\_base\_uri** (const **SerdEnv** \*env, **SerdURI** \*out)\
 **SerdStatus** **serd\_env\_set\_base\_uri** (**SerdEnv** \*env, const **SerdNode** \*uri)\
 **SerdStatus** **serd\_env\_set\_prefix** (**SerdEnv** \*env, const **SerdNode** \*name, const **SerdNode** \*uri)\
 **SerdStatus** **serd\_env\_set\_prefix\_from\_strings** (**SerdEnv** \*env, const uint8\_t \*name, const uint8\_t \*uri)\
 bool **serd\_env\_qualify** (const **SerdEnv** \*env, const **SerdNode** \*uri, **SerdNode** \*prefix, **SerdChunk** \*suffix)\
 **SerdStatus** **serd\_env\_expand** (const **SerdEnv** \*env, const **SerdNode** \*curie, **SerdChunk** \*uri\_prefix, **SerdChunk** \*uri\_suffix)\
 **SerdNode** **serd\_env\_expand\_node** (const **SerdEnv** \*env, const **SerdNode** \*node)\
 void **serd\_env\_foreach** (const **SerdEnv** \*env, **SerdPrefixSink** func, void \*handle)\

### Reader

**SerdReader** \* **serd\_reader\_new** (**SerdSyntax** syntax, void \*handle, void(\*free\_handle)(void \*), **SerdBaseSink** base\_sink, **SerdPrefixSink** prefix\_sink, **SerdStatementSink** statement\_sink, **SerdEndSink** end\_sink)\
 void **serd\_reader\_set\_strict** (**SerdReader** \*reader, bool strict)\
 void **serd\_reader\_set\_error\_sink** (**SerdReader** \*reader, **SerdErrorSink** error\_sink, void \*error\_handle)\
 void \* **serd\_reader\_get\_handle** (const **SerdReader** \*reader)\
 void **serd\_reader\_add\_blank\_prefix** (**SerdReader** \*reader, const uint8\_t \*prefix)\
 void **serd\_reader\_set\_default\_graph** (**SerdReader** \*reader, const **SerdNode** \*graph)\
 **SerdStatus** **serd\_reader\_read\_file** (**SerdReader** \*reader, const uint8\_t \*uri)\
 **SerdStatus** **serd\_reader\_start\_stream** (**SerdReader** \*reader, FILE \*file, const uint8\_t \*name, bool bulk)\
 **SerdStatus** **serd\_reader\_start\_source\_stream** (**SerdReader** \*reader, **SerdSource** read\_func, **SerdStreamErrorFunc** error\_func, void \*stream, const uint8\_t \*name, size\_t page\_size)\
 **SerdStatus** **serd\_reader\_read\_chunk** (**SerdReader** \*reader)\
 **SerdStatus** **serd\_reader\_end\_stream** (**SerdReader** \*reader)\
 **SerdStatus** **serd\_reader\_read\_file\_handle** (**SerdReader** \*reader, FILE \*file, const uint8\_t \*name)\
 **SerdStatus** **serd\_reader\_read\_source** (**SerdReader** \*reader, **SerdSource** source, **SerdStreamErrorFunc** error, void \*stream, const uint8\_t \*name, size\_t page\_size)\
 **SerdStatus** **serd\_reader\_read\_string** (**SerdReader** \*reader, const uint8\_t \*utf8)\
 void **serd\_reader\_free** (**SerdReader** \*reader)\

### Writer

**SerdWriter** \* **serd\_writer\_new** (**SerdSyntax** syntax, **SerdStyle** style, **SerdEnv** \*env, const **SerdURI** \*base\_uri, **SerdSink** ssink, void \*stream)\
 void **serd\_writer\_free** (**SerdWriter** \*writer)\
 **SerdEnv** \* **serd\_writer\_get\_env** (**SerdWriter** \*writer)\
 size\_t **serd\_file\_sink** (const void \*buf, size\_t len, void \*stream)\
 size\_t **serd\_chunk\_sink** (const void \*buf, size\_t len, void \*stream)\
 uint8\_t \* **serd\_chunk\_sink\_finish** (**SerdChunk** \*stream)\
 void **serd\_writer\_set\_error\_sink** (**SerdWriter** \*writer, **SerdErrorSink** error\_sink, void \*error\_handle)\
 void **serd\_writer\_chop\_blank\_prefix** (**SerdWriter** \*writer, const uint8\_t \*prefix)\
 **SerdStatus** **serd\_writer\_set\_base\_uri** (**SerdWriter** \*writer, const **SerdNode** \*uri)\
 **SerdStatus** **serd\_writer\_set\_root\_uri** (**SerdWriter** \*writer, const **SerdNode** \*uri)\
 **SerdStatus** **serd\_writer\_set\_prefix** (**SerdWriter** \*writer, const **SerdNode** \*name, const **SerdNode** \*uri)\
 **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)\
 **SerdStatus** **serd\_writer\_end\_anon** (**SerdWriter** \*writer, const **SerdNode** \*node)\
 **SerdStatus** **serd\_writer\_finish** (**SerdWriter** \*writer)\

## Data Structure Documentation

## struct SerdNode

A syntactic RDF node.

**Data Fields:**

const uint8\_t \* *buf* Value string. \

size\_t *n\_bytes* Size in bytes (not including null) \

size\_t *n\_chars* Length in characters (not including null) \

**SerdNodeFlags** *flags* Node flags (e.g. string properties) \

**SerdType** *type* Node type. \

## struct SerdChunk

An unterminated string fragment.

**Data Fields:**

const uint8\_t \* *buf* Start of chunk. \

size\_t *len* Length of chunk in bytes. \

## struct SerdError

An error description.

**Data Fields:**

**SerdStatus** *status* Error code. \

const uint8\_t \* *filename* File where error was encountered, or NULL. \

unsigned *line* Line where error was encountered, or 0. \

unsigned *col* Column where error was encountered. \

const char \* *fmt* Message format string (printf style) \

va\_list \* *args* Arguments for fmt. \

## struct SerdURI

A parsed URI.

This struct directly refers to chunks in other strings, it does not own any memory itself. Thus, URIs can be parsed and/or resolved against a base URI in-place without allocating memory.

**Data Fields:**

**SerdChunk** *scheme* Scheme. \

**SerdChunk** *authority* Authority. \

**SerdChunk** *path\_base* Path prefix if relative. \

**SerdChunk** *path* Path suffix. \

**SerdChunk** *query* Query. \

**SerdChunk** *fragment* Fragment. \

## Typedef Documentation

### typedef struct SerdEnvImpl SerdEnv

Environment. Represents the state required to resolve a CURIE or relative URI, e.g. the base URI and set of namespace prefixes at a particular point.

### typedef struct SerdReaderImpl SerdReader

RDF reader. Parses RDF by calling user-provided sink functions as input is consumed (much like an XML SAX parser).

### typedef struct SerdWriterImpl SerdWriter

RDF writer. Provides a number of functions to allow writing RDF syntax out to some stream. These functions are deliberately compatible with the sink functions used by SerdReader, so a reader can be directly connected to a writer to re-serialise a document with minimal overhead.

### typedef uint32\_t SerdStatementFlags

Bitwise OR of SerdStatementFlag values.

### typedef uint32\_t SerdNodeFlags

Bitwise OR of SerdNodeFlag values.

### typedef int(\* SerdStreamErrorFunc) (void \*stream)

Function to detect I/O stream errors. Identical semantics to `ferror`.

**Returns**

Non-zero if `stream` has encountered an error.

### typedef size\_t(\* SerdSource) (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.

### typedef size\_t(\* SerdSink) (const void \*buf, size\_t len, void \*stream)

Sink function for raw string output.

### typedef SerdStatus(\* SerdErrorSink) (void \*handle, const SerdError \*error)

Sink (callback) for errors.

**Parameters**

*handle* Handle for user data. \
 *error* Error description.

### typedef SerdStatus(\* SerdBaseSink) (void \*handle, const SerdNode \*uri)

Sink (callback) for base URI changes. Called whenever the base URI of the serialisation changes.

### typedef SerdStatus(\* SerdPrefixSink) (void \*handle, const SerdNode \*name, const SerdNode \*uri)

Sink (callback) for namespace definitions. Called whenever a prefix is defined in the serialisation.

### typedef SerdStatus(\* SerdStatementSink) (void \*handle, SerdStatementFlags flags, const SerdNode \*graph, const SerdNode \*subject, const SerdNode \*predicate, const SerdNode \*object, const SerdNode \*object\_datatype, const SerdNode \*object\_lang)

Sink (callback) for statements. Called for every RDF statement in the serialisation.

### typedef SerdStatus(\* SerdEndSink) (void \*handle, const SerdNode \*node)

Sink (callback) for anonymous node end markers. This is called to indicate that the anonymous node with the given `value` will no longer be referred to by any future statements (i.e. the anonymous serialisation of the node is finished).

## Enumeration Type Documentation

### enum SerdStatus

Return status code.

**Enumerator**

- *SERD\_SUCCESS*

  *No error.*

- *SERD\_FAILURE*

  *Non-fatal failure.*

- *SERD\_ERR\_UNKNOWN*

  *Unknown error.*

- *SERD\_ERR\_BAD\_SYNTAX*

  *Invalid syntax.*

- *SERD\_ERR\_BAD\_ARG*

  *Invalid argument.*

- *SERD\_ERR\_NOT\_FOUND*

  *Not found.*

- *SERD\_ERR\_ID\_CLASH*

  *Encountered clashing blank node IDs.*

- *SERD\_ERR\_BAD\_CURIE*

  *Invalid CURIE (e.g. prefix does not exist)*

- *SERD\_ERR\_INTERNAL*

  *Unexpected internal error (should not happen)*

### enum SerdSyntax

*RDF syntax type.*

**Enumerator**

- *SERD\_TURTLE*

  *Turtle - Terse RDF Triple Language (UTF-8).*

**See also**

`Turtle`

- *SERD\_NTRIPLES*

  *NTriples - Line-based RDF triples (ASCII).*

**See also**

`NTriples`

- *SERD\_NQUADS*

  *NQuads - Line-based RDF quads (UTF-8).*

**See also**

`NQuads`

- *SERD\_TRIG*

  *TriG - Terse RDF quads (UTF-8).*

**See also**

`Trig`

### enum SerdStatementFlag

*Flags indicating inline abbreviation information for a statement.*

**Enumerator**

- *SERD\_EMPTY\_S*

  *Empty blank node subject.*

- *SERD\_EMPTY\_O*

  *Empty blank node object.*

- *SERD\_ANON\_S\_BEGIN*

  *Start of anonymous subject.*

- *SERD\_ANON\_O\_BEGIN*

  *Start of anonymous object.*

- *SERD\_ANON\_CONT*

  *Continuation of anonymous node.*

- *SERD\_LIST\_S\_BEGIN*

  *Start of list subject.*

- *SERD\_LIST\_O\_BEGIN*

  *Start of list object.*

- *SERD\_LIST\_CONT*

  *Continuation of list.*

### enum SerdType

*Type of a syntactic RDF node. This is more precise than the type of an abstract RDF node. An abstract node is either a resource, literal, or blank. In syntax there are two ways to refer to a resource (by URI or CURIE) and two ways to refer to a blank (by ID or anonymously). Anonymous (inline) blank nodes are expressed using SerdStatementFlags rather than this type.*

**Enumerator**

- *SERD\_NOTHING*

  *The type of a nonexistent node. This type is useful as a sentinel, but is never emitted by the reader.*

- *SERD\_LITERAL*

  *Literal value. A literal optionally has either a language, or a datatype (not both).*

- *SERD\_URI*

  *URI (absolute or relative). Value is an unquoted URI string, which is either a relative reference with respect to the current base URI (e.g. 'foo/bar'), or an absolute URI (e.g. 'http://example.org/foo').*

**See also**

`RFC3986`*.*

- *SERD\_CURIE*

  *CURIE, a shortened URI. Value is an unquoted CURIE string relative to the current environment, e.g. 'rdf:type'.*

**See also**

`CURIE Syntax 1.0`

- *SERD\_BLANK*

  *A blank node. Value is a blank node ID, e.g. 'id3', which is meaningful only within this serialisation.*

**See also**

`Turtle nodeID `

### enum SerdNodeFlag

`Flags indicating certain string properties relevant to serialisation. `

**Enumerator**

- *SERD\_HAS\_NEWLINE*

  *Contains line breaks ('\\n' or '\\r')*

- *SERD\_HAS\_QUOTE*

  *Contains quotes (''')*

### enum SerdStyle

*Syntax style options. The style of the writer output can be controlled by ORing together values from this enumeration. Note that some options are only supported for some syntaxes (e.g. NTriples does not support abbreviation and is always ASCII).*

**Enumerator**

- *SERD\_STYLE\_ABBREVIATED*

  *Abbreviate triples when possible.*

- *SERD\_STYLE\_ASCII*

  *Escape all non-ASCII characters.*

- *SERD\_STYLE\_RESOLVED*

  *Resolve URIs against base URI.*

- *SERD\_STYLE\_CURIED*

  *Shorten URIs into CURIEs.*

- *SERD\_STYLE\_BULK*

  *Write output in pages.*

## Function Documentation

### void serd\_free (void \* ptr)

*Free memory allocated by Serd. This function exists because some systems require memory allocated by a library to be freed by code in the same library. It is otherwise equivalent to the standard C free() function.*

### const uint8\_t\* serd\_strerror (SerdStatus status)

*Return a string describing a status code.*

### size\_t serd\_strlen (const uint8\_t \* str, size\_t \* n\_bytes, SerdNodeFlags \* flags)

*Measure a UTF-8 string.*

**Returns**

*Length of* `str` *in characters (except NULL).*

**Parameters**

*str A null-terminated UTF-8 string.* \
 *n\_bytes (Output) Set to the size of* `str` *in bytes (except NULL).* \
 *flags (Output) Set to the applicable flags.*

### double serd\_strtod (const char \* str, char \*\* endptr)

*Parse a string to a double. The API of this function is identical to the standard C strtod function, except this function is locale-independent and always matches the lexical format used in the Turtle grammar (the decimal point is always '.').*

### void\* serd\_base64\_decode (const uint8\_t \* str, size\_t len, size\_t \* size)

*Decode a base64 string. This function can be used to deserialise a blob node created with* **serd\_node\_new\_blob()***.*

**Parameters**

*str Base64 string to decode.* \
 *len The length of* `str`*.* \
 *size Set to the size of the returned blob in bytes.*

**Returns**

*A newly allocated blob which must be freed with* **serd\_free()***.*

### const uint8\_t\* serd\_uri\_to\_path (const uint8\_t \* uri)

*Return the local path for* `uri`*, or NULL if* `uri` *is not a file URI. Note this (inappropriately named) function only removes the file scheme if necessary, and returns* `uri` *unmodified if it is an absolute path. Percent encoding and other issues are not handled, to properly convert a file URI to a path, use* **serd\_file\_uri\_parse()***.*

### uint8\_t\* serd\_file\_uri\_parse (const uint8\_t \* uri, uint8\_t \*\* hostname)

*Get the unescaped path and hostname from a file URI.*

**Parameters**

*uri A file URI.* \
 *hostname If non-NULL, set to the hostname, if present.*

**Returns**

*The path component of the URI.*

*The returned path and* `*hostname` *must be freed with* **serd\_free()***.*

### bool serd\_uri\_string\_has\_scheme (const uint8\_t \* utf8)

*Return true iff* `utf8` *starts with a valid URI scheme.*

### SerdStatus serd\_uri\_parse (const uint8\_t \* utf8, SerdURI \* out)

*Parse* `utf8`*, writing result to* `out`*.*

### void serd\_uri\_resolve (const SerdURI \* r, const SerdURI \* base, SerdURI \* t)

*Set target* `t` *to reference* `r` *resolved against* `base`*.*

**See also**

*http://tools.ietf.org/html/rfc3986#section-5.2.2*

### size\_t serd\_uri\_serialise (const SerdURI \* uri, SerdSink sink, void \* stream)

*Serialise* `uri` *with a series of calls to* `sink`*.*

### size\_t serd\_uri\_serialise\_relative (const SerdURI \* uri, const SerdURI \* base, const SerdURI \* root, SerdSink sink, void \* stream)

*Serialise* `uri` *relative to* `base` *with a series of calls to* `sink`*. The* `uri` *is written as a relative URI iff if it a child of* `base` *and* `root`*. The optional* `root` *parameter must be a prefix of* `base` *and can be used keep up-references ('../') within a certain namespace.*

### SerdNode serd\_node\_from\_string (SerdType type, const uint8\_t \* str)

*Make a (shallow) node from* `str`*. This measures, but does not copy,* `str`*. No memory is allocated.*

### SerdNode serd\_node\_from\_substring (SerdType type, const uint8\_t \* str, size\_t len)

*Make a (shallow) node from a prefix of* `str`*. This measures, but does not copy,* `str`*. No memory is allocated. Note that the returned node may not be null terminated.*

### SerdNode serd\_node\_copy (const SerdNode \* node)

*Make a deep copy of* `node`*.*

**Returns**

*a node that the caller must free with* **serd\_node\_free()***.*

### bool serd\_node\_equals (const SerdNode \* a, const SerdNode \* b)

*Return true iff* `a` *is equal to* `b`*.*

### SerdNode serd\_node\_new\_uri\_from\_node (const SerdNode \* uri\_node, const SerdURI \* base, SerdURI \* out)

*Simple wrapper for* **serd\_node\_new\_uri()** *to resolve a URI node.*

### SerdNode serd\_node\_new\_uri\_from\_string (const uint8\_t \* str, const SerdURI \* base, SerdURI \* out)

*Simple wrapper for* **serd\_node\_new\_uri()** *to resolve a URI string.*

### SerdNode serd\_node\_new\_file\_uri (const uint8\_t \* path, const uint8\_t \* hostname, SerdURI \* out, bool escape)

*Create a new file URI node from a file system path and optional hostname. Backslashes in Windows paths will be converted and '' will always be percent encoded. If* `escape` *is true, all other invalid characters will be percent encoded as well.*

*If* `path` *is relative,* `hostname` *is ignored. If* `out` *is not NULL, it will be set to the parsed URI.*

### SerdNode serd\_node\_new\_uri (const SerdURI \* uri, const SerdURI \* base, SerdURI \* out)

*Create a new node by serialising* `uri` *into a new string.*

**Parameters**

*uri The URI to serialise.*\
 *base Base URI to resolve* `uri` *against (or NULL for no resolution).*\
 *out Set to the parsing of the new URI (i.e. points only to memory owned by the new returned node).*

### SerdNode serd\_node\_new\_relative\_uri (const SerdURI \* uri, const SerdURI \* base, const SerdURI \* root, SerdURI \* out)

*Create a new node by serialising* `uri` *into a new relative URI.*

**Parameters**

*uri The URI to serialise.*\
 *base Base URI to make* `uri` *relative to, if possible.*\
 *root Root URI for resolution (see* **serd\_uri\_serialise\_relative()***).*\
 *out Set to the parsing of the new URI (i.e. points only to memory owned by the new returned node).*

### SerdNode serd\_node\_new\_decimal (double d, unsigned frac\_digits)

*Create a new node by serialising* `d` *into an xsd:decimal string. The resulting node will always contain a \`.', start with a digit, and end with a digit (i.e. will have a leading and/or trailing \`0' if necessary). It will never be in scientific notation. A maximum of* `frac_digits` *digits will be written after the decimal point, but trailing zeros will automatically be omitted (except one if* `d` *is a round integer).*

*Note that about 16 and 8 fractional digits are required to precisely represent a double and float, respectively.*

**Parameters**

*d The value for the new node.* \
 *frac\_digits The maximum number of digits after the decimal place.*

### SerdNode serd\_node\_new\_integer (int64\_t i)

*Create a new node by serialising* `i` *into an xsd:integer string.*

### SerdNode serd\_node\_new\_blob (const void \* buf, size\_t size, bool wrap\_lines)

*Create a node by serialising* `buf` *into an xsd:base64Binary string. This function can be used to make a serialisable node out of arbitrary binary data, which can be decoded using* **serd\_base64\_decode()***.*

**Parameters**

*buf Raw binary input data.* \
 *size Size of* `buf`*.* \
 *wrap\_lines Wrap lines at 76 characters to conform to RFC 2045.*

### void serd\_node\_free (SerdNode \* node)

*Free any data owned by* `node`*. Note that if* `node` *is itself dynamically allocated (which is not the case for nodes created internally by serd), it will not be freed.*

### SerdEnv\* serd\_env\_new (const SerdNode \* base\_uri)

*Create a new environment.*

### void serd\_env\_free (SerdEnv \* env)

*Free* `ns`*.*

### const SerdNode\* serd\_env\_get\_base\_uri (const SerdEnv \* env, SerdURI \* out)

*Get the current base URI.*

### SerdStatus serd\_env\_set\_base\_uri (SerdEnv \* env, const SerdNode \* uri)

*Set the current base URI.*

### SerdStatus serd\_env\_set\_prefix (SerdEnv \* env, const SerdNode \* name, const SerdNode \* uri)

*Set a namespace prefix.*

### SerdStatus serd\_env\_set\_prefix\_from\_strings (SerdEnv \* env, const uint8\_t \* name, const uint8\_t \* uri)

*Set a namespace prefix.*

### bool serd\_env\_qualify (const SerdEnv \* env, const SerdNode \* uri, SerdNode \* prefix, SerdChunk \* suffix)

*Qualify* `uri` *into a CURIE if possible.*

### SerdStatus serd\_env\_expand (const SerdEnv \* env, const SerdNode \* curie, SerdChunk \* uri\_prefix, SerdChunk \* uri\_suffix)

*Expand* `curie`*. Errors: SERD\_ERR\_BAD\_ARG if* `curie` *is not valid, or SERD\_ERR\_BAD\_CURIE if prefix is not defined in* `env`*.*

### SerdNode serd\_env\_expand\_node (const SerdEnv \* env, const SerdNode \* node)

*Expand* `node`*, which must be a CURIE or URI, to a full URI. Returns null if* `node` *can not be expanded.*

### void serd\_env\_foreach (const SerdEnv \* env, SerdPrefixSink func, void \* handle)

*Call* `func` *for each prefix defined in* `env`*.*

### SerdReader\* serd\_reader\_new (SerdSyntax syntax, void \* handle, void(\*)(void \*) free\_handle, SerdBaseSink base\_sink, SerdPrefixSink prefix\_sink, SerdStatementSink statement\_sink, SerdEndSink end\_sink)

*Create a new RDF reader.*

### 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.*

### 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\_get\_handle (const SerdReader \* reader)

*Return the* `handle` *passed to* **serd\_reader\_new()***.*

### 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 (e.g. a store, or other files). 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.*

### 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).*

### SerdStatus serd\_reader\_read\_file (SerdReader \* reader, const uint8\_t \* uri)

*Read a file at a given* `uri`*.*

### 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.*

### 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\_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\_end\_stream (SerdReader \* reader)

*Finish an incremental read from a file handle.*

### 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\_free (SerdReader \* reader)

*Free* `reader`*.*

### 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* `stream` *parameter 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* **SerdChunk** *which is resized as necessary with realloc(). The* `stream` *parameter must point to an initialized* **SerdChunk***. When the write is finished, the string should be retrieved with* **serd\_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_sink` *will be called with* `handle` *as 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.*

### SerdStatus serd\_writer\_set\_base\_uri (SerdWriter \* writer, const SerdNode \* uri)

*Set the current output base URI (and emit 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.*

## Variable Documentation

### const SerdURI SERD\_URI\_NULL` [static]`

**Initial value:**

```
= {
    {NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0}
}
```

### const SerdNode SERD\_NODE\_NULL = { NULL, 0, 0, 0, SERD\_NOTHING }` [static]`

## Author

*Generated by Doxygen for Serd from the source code and modified by Dennis Braun \<d\_braun@kabelmail.de\>.*
