Serializers

## Serializers Serializers — RDF serializers from triples to syntax. |

## Functions

const raptor_syntax_description * | librdf_serializer_get_description ()
int | librdf_serializer_enumerate ()
void | librdf_serializer_register_factory ()
librdf_serializer * | librdf_new_serializer ()
librdf_serializer * | librdf_new_serializer_from_factory ()
void | librdf_free_serializer ()
int | librdf_serializer_check_name ()
int | librdf_serializer_serialize_model ()
int | librdf_serializer_serialize_model_to_file_handle ()
int | librdf_serializer_serialize_model_to_file ()
unsigned char * | librdf_serializer_serialize_model_to_string ()
unsigned char * | librdf_serializer_serialize_model_to_counted_string ()
int | librdf_serializer_serialize_model_to_iostream ()
unsigned char * | librdf_serializer_serialize_stream_to_counted_string ()
int | librdf_serializer_serialize_stream_to_file ()
int | librdf_serializer_serialize_stream_to_file_handle ()
int | librdf_serializer_serialize_stream_to_iostream ()
unsigned char * | librdf_serializer_serialize_stream_to_string ()
void | librdf_serializer_set_error ()
void | librdf_serializer_set_warning ()
librdf_node * | librdf_serializer_get_feature ()
int | librdf_serializer_set_feature ()
int | librdf_serializer_set_namespace ()

## Types and Values

typedef | librdf_serializer
typedef | librdf_serializer_factory

## Description

Provides class to create serializers to turn RDF graphs into syntax in either files or strings. Serializer features can be set, which are passed down to Raptor and errors and warnings that are returned can be retrieved by callbacks.

## Functions

### librdf_serializer_get_description ()

    const raptor_syntax_description *
    librdf_serializer_get_description (librdf_world *world,
                                       unsigned int counter);

Get serializer descriptive syntax information

#### Parameters

world | world object |
counter | index into the list of serializers |

#### Returns

description or NULL if counter is out of range

### librdf_serializer_enumerate ()

    int
    librdf_serializer_enumerate (librdf_world *world,
                                 const unsigned int counter,
                                 const char **name,
                                 const char **label);

`librdf_serializer_enumerate` is deprecated and should not be used in newly-written code.

Get information on serializers.

`Deprecated` : use `librdf_serializer_get_description()` to return more information in a static structure.

#### Parameters

world | redland world object |
counter | index into the list of serializers |
name | pointer to store the name of the serializer (or NULL) |
label | pointer to store syntax readable label (or NULL) |

#### Returns

non 0 on failure of if counter is out of range

### librdf_serializer_register_factory ()

    void
    librdf_serializer_register_factory (librdf_world *world,
                                        const char *name,
                                        const char *label,
                                        const char *mime_type,
                                        const unsigned char *uri_string,
                                        void (*factory) (librdf_serializer_factory*));

Register a serializer factory .

#### Parameters

world | redland world object |
name | the name of the serializer |
label | the label of the serializer (optional) |
mime_type | MIME type of the syntax (optional) |
uri_string | URI of the syntax (optional) |
factory | function to be called to register the factor parameters |

### librdf_new_serializer ()

    librdf_serializer *
    librdf_new_serializer (librdf_world *world,
                           const char *name,
                           const char *mime_type,
                           librdf_uri *type_uri);

Constructor - create a new librdf_serializer object.

#### Parameters

world | redland world object |
name | the serializer factory name (or NULL or empty string if don't care) |
mime_type | the MIME type of the syntax (NULL if not used) |
type_uri | URI of syntax (NULL if not used) |

#### Returns

new librdf_serializer object or NULL

### librdf_new_serializer_from_factory ()

    librdf_serializer *
    librdf_new_serializer_from_factory (librdf_world *world,
                                        librdf_serializer_factory *factory);

Constructor - create a new librdf_serializer object.

#### Parameters

world | redland world object |
factory | the serializer factory to use to create this serializer |

#### Returns

new librdf_serializer object or NULL

### librdf_free_serializer ()

    void
    librdf_free_serializer (librdf_serializer *serializer);

Destructor - destroys a librdf_serializer object.

#### Parameters

serializer | the serializer |

### librdf_serializer_check_name ()

    int
    librdf_serializer_check_name (librdf_world *world,
                                  const char *name);

Check if a serializer name is known

#### Parameters

world | redland world object |
name | name of serializer |

#### Returns

non 0 if name is a known serializer

### librdf_serializer_serialize_model ()

    int
    librdf_serializer_serialize_model (librdf_serializer *serializer,
                                       FILE *handle,
                                       librdf_uri *base_uri,
                                       librdf_model *model);

`librdf_serializer_serialize_model` is deprecated and should not be used in newly-written code.

`Deprecated` : Use `librdf_serializer_serialize_model_to_file_handle()`

Write a serialized librdf_model to a FILE*.

#### Parameters

serializer | the serializer |
handle | file handle to serialize to |
base_uri | the base URI to use (or NULL) |
model | the librdf_model model to use |

#### Returns

non 0 on failure

### librdf_serializer_serialize_model_to_file_handle ()

    int
    librdf_serializer_serialize_model_to_file_handle
                                   (librdf_serializer *serializer,
                                    FILE *handle,
                                    librdf_uri *base_uri,
                                    librdf_model *model);

Write a serialized librdf_model to a FILE*.

#### Parameters

serializer | the serializer |
handle | file handle to serialize to |
base_uri | the base URI to use (or NULL) |
model | the librdf_model model to use |

#### Returns

non 0 on failure

### librdf_serializer_serialize_model_to_file ()

    int
    librdf_serializer_serialize_model_to_file
                                   (librdf_serializer *serializer,
                                    const char *name,
                                    librdf_uri *base_uri,
                                    librdf_model *model);

Write a serialized librdf_model to a file.

#### Parameters

serializer | the serializer |
name | filename to serialize to |
base_uri | the base URI to use (or NULL) |
model | the librdf_model model to use |

#### Returns

non 0 on failure

### librdf_serializer_serialize_model_to_string ()

    unsigned char *
    librdf_serializer_serialize_model_to_string
                                   (librdf_serializer *serializer,
                                    librdf_uri *base_uri,
                                    librdf_model *model);

Write a serialized librdf_model to a string. The returned string must be freed by the caller using `librdf_free_memory()`.

#### Parameters

serializer | the serializer |
base_uri | the base URI to use (or NULL) |
model | the librdf_model model to use |

#### Returns

NULL on failure

### librdf_serializer_serialize_model_to_counted_string ()

    unsigned char *
    librdf_serializer_serialize_model_to_counted_string
                                   (librdf_serializer *serializer,
                                    librdf_uri *base_uri,
                                    librdf_model *model,
                                    size_t *length_p);

Write a serialized librdf_model to a counted string. The returned string must be freed by the caller using `librdf_free_memory()`.

#### Parameters

serializer | the serializer |
base_uri | the base URI to use (or NULL) |
model | the librdf_model model to use |
length_p | pointer to store length or NULL |

#### Returns

non 0 on failure

### librdf_serializer_serialize_model_to_iostream ()

    int
    librdf_serializer_serialize_model_to_iostream
                                   (librdf_serializer *serializer,
                                    librdf_uri *base_uri,
                                    librdf_model *model,
                                    raptor_iostream *iostr);

Write a serialized librdf_model to a raptor_iostream. This function takes ownership of the iostream and frees it.

#### Parameters

serializer | the serializer |
base_uri | the base URI to use (or NULL) |
model | the librdf_model model to use |
iostr | the raptor_iostream to write to |

#### Returns

non-0 on failure

### librdf_serializer_serialize_stream_to_counted_string ()

    unsigned char *
    librdf_serializer_serialize_stream_to_counted_string
                                   (librdf_serializer *serializer,
                                    librdf_uri *base_uri,
                                    librdf_stream *stream,
                                    size_t *length_p);

Write a librdf_stream to a counted string. Caller should free the string with `librdf_free_memory()`.

#### Parameters

serializer | the serializer |
base_uri | the base URI to use (or NULL) |
stream | the librdf_stream stream to use |
length_p | pointer to store length or NULL |

#### Returns

stream as string or NULL on failure

### librdf_serializer_serialize_stream_to_file ()

    int
    librdf_serializer_serialize_stream_to_file
                                   (librdf_serializer *serializer,
                                    const char *name,
                                    librdf_uri *base_uri,
                                    librdf_stream *stream);

Write a librdf_stream to a file.

#### Parameters

serializer | the serializer |
name | filename to serialize to |
base_uri | the base URI to use (or NULL) |
stream | the librdf_stream stream to use |

#### Returns

non 0 on failure

### librdf_serializer_serialize_stream_to_file_handle ()

    int
    librdf_serializer_serialize_stream_to_file_handle
                                   (librdf_serializer *serializer,
                                    FILE *handle,
                                    librdf_uri *base_uri,
                                    librdf_stream *stream);

Write a librdf_stream to a FILE*.

#### Parameters

serializer | the serializer |
handle | file handle to serialize to |
base_uri | the base URI to use (or NULL) |
stream | the librdf_stream model to use |

#### Returns

non 0 on failure

### librdf_serializer_serialize_stream_to_iostream ()

    int
    librdf_serializer_serialize_stream_to_iostream
                                   (librdf_serializer *serializer,
                                    librdf_uri *base_uri,
                                    librdf_stream *stream,
                                    raptor_iostream *iostr);

Write a librdf_stream to a raptor_iostream. This function takes ownership of the iostream and frees it.

#### Parameters

serializer | the serializer |
base_uri | the base URI to use (or NULL) |
stream | the librdf_stream stream to use |
iostr | the raptor_iostream to write to |

#### Returns

non-0 on failure

### librdf_serializer_serialize_stream_to_string ()

    unsigned char *
    librdf_serializer_serialize_stream_to_string
                                   (librdf_serializer *serializer,
                                    librdf_uri *base_uri,
                                    librdf_stream *stream);

Write a librdf_stream to a string.

#### Parameters

serializer | the serializer |
base_uri | the base URI to use (or NULL) |
stream | the librdf_stream stream to use |

#### Returns

NULL on failure

### librdf_serializer_set_error ()

    void
    librdf_serializer_set_error (librdf_serializer *serializer,
                                 void *user_data,
                                 void (*error_fn) (void *user_data, const char *msg, ...));

`Deprecated` : Does nothing

Set the serializer error handling function.

#### Parameters

serializer | the serializer |
user_data | user data to pass to function |
error_fn | pointer to the function |

### librdf_serializer_set_warning ()

    void
    librdf_serializer_set_warning (librdf_serializer *serializer,
                                   void *user_data,
                                   void (*warning_fn) (void *user_data, const char *msg, ...));

`Deprecated` : Does nothing

Set the serializer warning handling function.

#### Parameters

serializer | the serializer |
user_data | user data to pass to function |
warning_fn | pointer to the function |

### librdf_serializer_get_feature ()

    librdf_node *
    librdf_serializer_get_feature (librdf_serializer *serializer,
                                   librdf_uri *feature);

Get the value of a serializer feature.

#### Parameters

serializer | serializer object |
feature | URI of feature |

#### Returns

the value of the feature or NULL if no such feature exists or the value is empty.

### librdf_serializer_set_feature ()

    int
    librdf_serializer_set_feature (librdf_serializer *serializer,
                                   librdf_uri *feature,
                                   librdf_node *value);

Set the value of a serializer feature.

#### Parameters

serializer | serializer object |
feature | URI of feature |
value | value to set |

#### Returns

non 0 on failure (negative if no such feature)

### librdf_serializer_set_namespace ()

    int
    librdf_serializer_set_namespace (librdf_serializer *serializer,
                                     librdf_uri *uri,
                                     const char *prefix);

Set a namespace URI/prefix mapping.

#### Parameters

serializer | serializer object |
uri | URI of namespace or NULL |
prefix | prefix to use or NULL |

#### Returns

non 0 on failure

## Types and Values

### librdf_serializer

    typedef struct librdf_serializer_s librdf_serializer;

Redland serializer class.

### librdf_serializer_factory

    typedef struct librdf_serializer_factory_s librdf_serializer_factory;

Redland serializer factory class.