Volksdata 1.0b7
RDF library
Loading...
Searching...
No Matches
codec_interface.h
Go to the documentation of this file.
1
51
52#ifndef VOLK_CODEC_BASE_H
53#define VOLK_CODEC_BASE_H
54
55#include "volksdata/graph.h"
56
64#ifdef VOLK_RDF_STREAM_CHUNK_SIZE
65#define CHUNK_SIZE VOLK_RDF_STREAM_CHUNK_SIZE
66#else
67#define CHUNK_SIZE 4096
68#endif
69
73/* TODO A plain string will suffice for now.
74typedef struct parse_error_t {
75 unsigned int line; // Line number where the error occurred.
76 unsigned int linec; // Position in line of the offending token.
77 char * token; // String representation of the token.
78} VOLK_ParseError;
79*/
80
82typedef enum codec_flags_t {
87
102
103/*
104 * Common utility functions.
105 */
106
112inline uint8_t
113*uint8_dup (const uint8_t *str)
114{ return (uint8_t *) strdup ((char *) str); }
115
116
122inline uint8_t
123*uint8_ndup (const uint8_t *str, size_t size)
124{ return (uint8_t *) strndup ((char *) str, size); }
125
126
136escape_lit (const char *in, char **out);
137
138
143static inline char
144escape_char (const char c) {
145 switch (c) {
146 case '\t': return 't';
147 case '\b': return 'b';
148 case '\n': return 'n';
149 case '\r': return 'r';
150 case '\f': return 'f';
151 default: return c;
152 }
153}
154
155
168inline char
169unescape_char (const char c)
170{
171 switch (c) {
172 case 't': return '\t';
173 case 'b': return '\b';
174 case 'n': return '\n';
175 case 'r': return '\r';
176 case 'f': return '\f';
177 default: return c;
178 }
179}
180
181
190uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size);
191
192
202char *fmt_header (char *pfx);
203
204
205/*
206 * Interface prototypes.
207 */
208
209
210/*
211 * Decoding functions.
212 */
213
225typedef VOLK_rc (*term_enc_fn_t)(const VOLK_Term *term, char **rep);
226
227
245typedef void * (*encode_gr_init_fn_t)(
246 const VOLK_Graph *gr, VOLK_CodecFlags flags);
247
248
268typedef VOLK_rc (*encode_gr_iter_fn_t)(void *it, char **res);
269
270
279typedef void (*encode_gr_done_fn_t)(void *it);
280
281
296typedef void * (*encode_ds_init_fn_t)(void);
297
298
319 void *it, const VOLK_Graph *gr, char **res);
320
321
332typedef void (*encode_ds_done_fn_t)(void *it);
333
334
348typedef void * (*encode_store_init_fn_t)(VOLK_Store *store);
349
350
368typedef VOLK_rc (*encode_store_iter_fn_t)(void *it, char **res);
369
370
379typedef void (*encode_store_done_fn_t)(void *it);
380
381
382/*
383 * Decoding functions.
384 */
385
386
399typedef VOLK_rc (*decode_term_fn_t)(const char *rep, VOLK_Term **term);
400
401
427 FILE *fh, const char *sh, VOLK_Graph *gr, size_t *ct, char **err);
428
429
441typedef void * (*decode_ds_init_fn_t)(FILE *fh, const char *sh);
442
443
462 void *it, VOLK_Graph **gr, size_t *ct, char **err);
463
464
469typedef void (*decode_ds_done_fn_t)(void *it);
470
471
535
537
538#endif // VOLK_CODEC_BASE_H
char escape_char(const char c)
VOLK_rc(* decode_gr_fn_t)(FILE *fh, const char *sh, VOLK_Graph *gr, size_t *ct, char **err)
Prototype for decoding a complete RDF document file into a graph.
void(* encode_ds_done_fn_t)(void *it)
Finalize a dataset encoding operation.
uint8_t * uint8_ndup(const uint8_t *str, size_t size)
strndup() for unsigned char.
VOLK_rc(* decode_term_fn_t)(const char *rep, VOLK_Term **term)
Prototype for decoding a string into a VOLK_Term.
VOLK_rc(* decode_ds_iter_fn_t)(void *it, VOLK_Graph **gr, size_t *ct, char **err)
Prototype for decoding one graph in a dataset.
void *(* encode_gr_init_fn_t)(const VOLK_Graph *gr, VOLK_CodecFlags flags)
Initialize a graph encoding loop.
void(* encode_store_done_fn_t)(void *it)
Finalize a store encoding operation.
void(* decode_ds_done_fn_t)(void *it)
Prototype for finalizing a dataset decoder iterator.
void *(* encode_store_init_fn_t)(VOLK_Store *store)
Initialize a store encoding loop.
void *(* decode_ds_init_fn_t)(FILE *fh, const char *sh)
Prototype for initializing a dataset decoding loop.
char * fmt_header(char *pfx)
Format an informational header.
VOLK_CodecFlags
Parse error information.
VOLK_CodecFeatures
Feature flags applicable to a codec.
char unescape_char(const char c)
Unescape a single character.
VOLK_rc(* encode_store_iter_fn_t)(void *it, char **res)
Perform one store encoding iteration.
void *(* encode_ds_init_fn_t)(void)
Initialize a dataset encoding loop.
VOLK_rc escape_lit(const char *in, char **out)
Add escape character (backslash) to illegal literal characters.
VOLK_rc(* term_enc_fn_t)(const VOLK_Term *term, char **rep)
Term encoder callback type.
uint8_t * uint8_dup(const uint8_t *str)
strdup() for unsigned char.
VOLK_rc(* encode_ds_iter_fn_t)(void *it, const VOLK_Graph *gr, char **res)
Perform one dataset encoding iteration.
void(* encode_gr_done_fn_t)(void *it)
Finalize a graph encoding operation.
VOLK_rc(* encode_gr_iter_fn_t)(void *it, char **res)
Perform one graph encoding iteration.
uint8_t * unescape_unicode(const uint8_t *esc_str, size_t size)
Replace \uxxxx and \Uxxxxxxxx with Unicode bytes.
@ VOLK_CODEC_NO_PROLOG
Do not generate prolog.
@ VOLK_CODEC_TXN
@ VOLK_CODEC_FEAT_DECODE_GR
Supports decoding a graph.
@ VOLK_CODEC_FEAT_ENCODE_GR
Supports encoding a graph.
@ VOLK_CODEC_FEAT_ENCODE_DS
Supports encoding a data set.
@ VOLK_CODEC_FEAT_ENCODE_STORE
Supports encoding a whole store.
@ VOLK_CODEC_FEAT_DECODE_TERM
Supports decoding a single term.
@ VOLK_CODEC_FEAT_ENCODE_TERM
Supports encoding a single term.
@ VOLK_CODEC_FEAT_DECODE_DS
Supports decoding a data set.
@ VOLK_CODEC_FEAT_DECODE_STORE
Supports decoding a whole store.
char * strdup(const char *src)
Replacement for GNU strdup.
Definition core.c:109
char * strndup(const char *src, size_t max)
Replacement for GNU strndup.
Definition core.c:92
int VOLK_rc
Definition core.h:79
Codec structure.
decode_ds_iter_fn_t decode_dset_iter
dataset decoder iteration.
encode_ds_init_fn_t encode_dset_init
dataset encoder initialization.
encode_store_init_fn_t encode_store_init
store encoder initialization.
encode_ds_done_fn_t encode_dset_done
dataset encoder finalization.
char extension[8]
Serialized file extension.
decode_ds_init_fn_t decode_dset_init
dataset decoder initialization.
encode_store_done_fn_t encode_store_done
store encoder finalization.
term_enc_fn_t encode_term
Feature flags.
decode_gr_fn_t decode_graph
Graph decoder function.
encode_gr_done_fn_t encode_graph_done
Graph encoder finalization.
encode_gr_init_fn_t encode_graph_init
Graph encoder initialization.
encode_ds_iter_fn_t encode_dset_iter
dataset encoder iteration.
VOLK_CodecFeatures features
encode_store_iter_fn_t encode_store_iter
store encoder iteration.
decode_term_fn_t decode_term
Term decoder function.
decode_ds_done_fn_t decode_dset_done
dataset decoder finalization.
char name[16]
Name of the codec.
char mimetype[32]
MIME type associated with the codec.
encode_gr_iter_fn_t encode_graph_iter
Graph encoder iteration.
Store structure.
Definition store.h:59
RDF term.
Definition term.h:62