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
60
67
75#ifdef VOLK_RDF_STREAM_CHUNK_SIZE
76#define CHUNK_SIZE VOLK_RDF_STREAM_CHUNK_SIZE
77#else
78#define CHUNK_SIZE 4096
79#endif
80
84/* TODO A plain string will suffice for now.
85typedef struct parse_error_t {
86 unsigned int line; // Line number where the error occurred.
87 unsigned int linec; // Position in line of the offending token.
88 char * token; // String representation of the token.
89} VOLK_ParseError;
90*/
91
93typedef enum codec_flags_t {
102
117
118/*
119 * Common utility functions.
120 */
121
127inline uint8_t
128*uint8_dup (const uint8_t *str)
129{ return (uint8_t *) strdup ((char *) str); }
130
131
137inline uint8_t
138*uint8_ndup (const uint8_t *str, size_t size)
139{ return (uint8_t *) strndup ((char *) str, size); }
140
141
151escape_lit (const char *in, char **out);
152
153
158static inline char
159escape_char (const char c) {
160 switch (c) {
161 case '\t': return 't';
162 case '\b': return 'b';
163 case '\n': return 'n';
164 case '\r': return 'r';
165 case '\f': return 'f';
166 default: return c;
167 }
168}
169
170
183inline char
184unescape_char (const char c)
185{
186 switch (c) {
187 case 't': return '\t';
188 case 'b': return '\b';
189 case 'n': return '\n';
190 case 'r': return '\r';
191 case 'f': return '\f';
192 default: return c;
193 }
194}
195
196
205uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size);
206
207
217char *fmt_header (char *pfx);
218
219
220/*
221 * Interface prototypes.
222 */
223
224
225/*
226 * Decoding functions.
227 */
228
240typedef VOLK_rc (*encode_term_fn_t)(const VOLK_Term *term, char **rep);
241
242
260typedef void * (*encode_gr_init_fn_t)(const VOLK_Graph *gr, void *udata);
261
262
282typedef VOLK_rc (*encode_gr_iter_fn_t)(void *it, char **res);
283
284
293typedef void (*encode_gr_done_fn_t)(void *it);
294
295
310typedef void * (*encode_ds_init_fn_t)(const VOLK_Graph **dset);
311
312
333 void *it, const VOLK_Graph *gr, char **res);
334
335
346typedef void (*encode_ds_done_fn_t)(void *it);
347
348
362typedef void * (*encode_store_init_fn_t)(VOLK_Store *store);
363
364
382typedef VOLK_rc (*encode_store_iter_fn_t)(void *it, char **res);
383
384
389typedef void (*encode_store_done_fn_t)(void *it);
390
391
392/*
393 * Decoding functions.
394 */
395
396
409typedef VOLK_rc (*decode_term_fn_t)(const char *rep, VOLK_Term **term);
410
411
437 FILE *fh, const char *sh, VOLK_Graph *gr, size_t *ct, char **err);
438
439
463 FILE *fh, const char *sh, VOLK_Store *store, void *udata,
464 size_t *ct, char **err_p);
465
466
480//typedef void * (*decode_ds_init_fn_t)(FILE *fh, const char *sh);
481
482
502//typedef VOLK_rc (*decode_ds_iter_fn_t)(
503// void *it, VOLK_Graph **gr, size_t *ct, char **err);
504
505
512//typedef void (*decode_ds_done_fn_t)(void *it);
513
514
580
582
583#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.
void *(* encode_ds_init_fn_t)(const VOLK_Graph **dset)
Initialize a dataset encoding loop.
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.
void *(* encode_gr_init_fn_t)(const VOLK_Graph *gr, void *udata)
Initialize a graph encoding loop.
void(* encode_store_done_fn_t)(void *it)
Finalize a store encoding operation.
void *(* encode_store_init_fn_t)(VOLK_Store *store)
Initialize a store encoding loop.
char * fmt_header(char *pfx)
Format an informational header.
VOLK_CodecFlags
Parse error information.
VOLK_CodecFeatures
Feature flags applicable to a codec.
VOLK_rc(* encode_term_fn_t)(const VOLK_Term *term, char **rep)
Term encoder prototype.
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.
VOLK_rc escape_lit(const char *in, char **out)
Add escape character (backslash) to illegal literal characters.
VOLK_rc(* decode_ds_fn_t)(FILE *fh, const char *sh, VOLK_Store *store, void *udata, size_t *ct, char **err_p)
Prototype for decoding a dataset.
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.
@ CODEC_EXT_TXN
@ VOLK_CODEC_INDENT
@ 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
Prototype for initializing a dataset decoding loop.
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.
encode_term_fn_t encode_term
Feature flags.
char extension[8]
Serialized file extension.
encode_store_done_fn_t encode_store_done
store encoder finalization.
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_fn_t decode_dset
dataset decoder initialization.
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