Volksdata 1.0b7
RDF library
Loading...
Searching...
No Matches
codec.h
Go to the documentation of this file.
1#ifndef VOLK_CODEC_BASE_H
2#define VOLK_CODEC_BASE_H
3
4#include "volksdata/graph.h"
5
13#ifdef VOLK_RDF_STREAM_CHUNK_SIZE
14#define CHUNK_SIZE VOLK_RDF_STREAM_CHUNK_SIZE
15#else
16#define CHUNK_SIZE 4096
17#endif
18
19
20/*
21 * Define supported codecs.
22 *
23 * Add new codec implementations to this table.
24 */
25#define CODEC_TBL \
26/* #enum suffix #fmt #codec if */ \
27 ENTRY( NT, nt, nt_codec ) \
28 ENTRY( TTL, ttl, ttl_codec ) \
29
30
32typedef enum codec_type {
33#define ENTRY(a, b, c) \
34 VOLK_CODEC_##a,
36#undef ENTRY
38typedef struct codec_t VOLK_Codec;
39
40
42typedef struct ttl_parser_state {
43 VOLK_GraphIterator * it;
46 size_t ct;
49
53/* TODO A plain string will suffice for now.
54typedef struct parse_error_t {
55 unsigned int line; // Line number where the error occurred.
56 unsigned int linec; // Position in line of the offending token.
57 char * token; // String representation of the token.
58} VOLK_ParseError;
59*/
60
61
62/*
63 * Common utility functions.
64 */
65
71inline uint8_t
72*uint8_dup (const uint8_t *str)
73{ return (uint8_t *) strdup ((char *) str); }
74
75
81inline uint8_t
82*uint8_ndup (const uint8_t *str, size_t size)
83{ return (uint8_t *) strndup ((char *) str, size); }
84
85
95escape_lit (const char *in, char **out);
96
97
102static inline char
103escape_char (const char c) {
104 switch (c) {
105 case '\t': return 't';
106 case '\b': return 'b';
107 case '\n': return 'n';
108 case '\r': return 'r';
109 case '\f': return 'f';
110 default: return c;
111 }
112}
113
114
127inline char
128unescape_char (const char c)
129{
130 switch (c) {
131 case 't': return '\t';
132 case 'b': return '\b';
133 case 'n': return '\n';
134 case 'r': return '\r';
135 case 'f': return '\f';
136 default: return c;
137 }
138}
139
140
149uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size);
150
151
161char *fmt_header (char *pfx);
162
164
165
170
171/*
172inline const VOLK_Codec *
173codec_by_fmt (const char *fmt)
174{
175#define ENTRY(a, b, c) \
176 if str
177CODEC_TBL
178#undef ENTRY
179}
180*/
181
182/*
183 * Interface prototypes.
184 */
185
197typedef VOLK_rc (*term_enc_fn_t)(const VOLK_Term *term, char **rep);
198
199
216typedef void * (*gr_encode_init_fn_t)(const VOLK_Graph *gr);
217
218
237typedef VOLK_rc (*gr_encode_iter_fn_t)(void *it, char **res);
238
239
248typedef void (*gr_encode_done_fn_t)(void *it);
249
250
263typedef VOLK_rc (*term_decode_fn_t)(const char *rep, VOLK_Term **term);
264
265
293 FILE *fh, const char *sh, VOLK_Graph **gr, size_t *ct, char **err);
294
295
334
335
336#endif // VOLK_CODEC_BASE_H
char escape_char(const char c)
void(* gr_encode_done_fn_t)(void *it)
Finalize an encoding operation.
Definition codec.h:248
VOLK_rc(* gr_decode_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.
Definition codec.h:292
VOLK_rc(* gr_encode_iter_fn_t)(void *it, char **res)
Perform one encoding iteration.
Definition codec.h:237
VOLK_rc(* term_enc_fn_t)(const VOLK_Term *term, char **rep)
Term encoder callback type.
Definition codec.h:197
VOLK_rc(* term_decode_fn_t)(const char *rep, VOLK_Term **term)
Prototype for decoding a string into a VOLK_Term.
Definition codec.h:263
void *(* gr_encode_init_fn_t)(const VOLK_Graph *gr)
Initialize a graph encoding loop.
Definition codec.h:216
uint8_t * uint8_ndup(const uint8_t *str, size_t size)
strndup() for unsigned char.
Definition codec.h:82
char * fmt_header(char *pfx)
Format an informational header.
Definition codec.c:116
char unescape_char(const char c)
Unescape a single character.
Definition codec.h:128
VOLK_rc escape_lit(const char *in, char **out)
Add escape character (backslash) to illegal literal characters.
Definition codec.c:81
#define CODEC_TBL
Definition codec.h:25
uint8_t * uint8_dup(const uint8_t *str)
Parse error information.
Definition codec.h:72
uint8_t * unescape_unicode(const uint8_t *esc_str, size_t size)
Replace \uxxxx and \Uxxxxxxxx with Unicode bytes.
Definition codec.c:11
VOLK_CodecType
Codec types. All prefixed with VOLK_CODEC_.
Definition codec.h:32
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
Parser state.
Definition codec.h:42
VOLK_GraphIterator * it
Iterator used to build the graph.
Definition codec.h:43
VOLK_rc rc
Internal return code.
Definition codec.h:47
size_t ct
Statements parsed.
Definition codec.h:46
VOLK_Term * base
Base IRI used in the document.
Definition codec.h:44
VOLK_Term * lms
Link map subject.
Definition codec.h:45
RDF term.
Definition term.h:62
Codec structure.
Definition codec.h:318
gr_encode_done_fn_t encode_graph_done
Graph encoder finalization.
Definition codec.h:328
gr_decode_fn_t decode_graph
Graph decoder function.
Definition codec.h:332
char extension[8]
Serialized file extension.
Definition codec.h:321
term_decode_fn_t decode_term
Term decoder function.
Definition codec.h:331
term_enc_fn_t encode_term
Term encoder function.
Definition codec.h:324
gr_encode_init_fn_t encode_graph_init
Graph encoder initialization.
Definition codec.h:326
gr_encode_iter_fn_t encode_graph_iter
Graph encoder iteration.
Definition codec.h:327
char name[16]
Name of the codec.
Definition codec.h:319
char mimetype[32]
MIME type associated with the codec.
Definition codec.h:320