123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- #ifndef _LSUP_CODEC_BASE_H
- #define _LSUP_CODEC_BASE_H
- #include "graph.h"
- #ifdef LSUP_RDF_STREAM_CHUNK_SIZE
- #define CHUNK_SIZE LSUP_RDF_STREAM_CHUNK_SIZE
- #else
- #define CHUNK_SIZE 8192
- #endif
- typedef struct codec_t LSUP_Codec;
- typedef struct {
- LSUP_GraphIterator * it;
- LSUP_NSMap * nsm;
- LSUP_Term * base;
- size_t ct;
- LSUP_rc rc;
- } LSUP_TTLParserState;
- typedef LSUP_rc (*term_enc_fn_t)(
- const LSUP_Term *term, const LSUP_NSMap *nsm, char **rep);
- typedef void * (*gr_encode_init_fn_t)(const LSUP_Graph *gr);
- typedef LSUP_rc (*gr_encode_iter_fn_t)(void *it, char **res);
- typedef void (*gr_encode_done_fn_t)(void *it);
- typedef LSUP_rc (*term_decode_fn_t)(
- const char *rep, const LSUP_NSMap *nsm, LSUP_Term **term);
- typedef LSUP_rc (*gr_decode_fn_t)(
- FILE *rep, LSUP_Graph **gr, size_t *ct, char **err);
- struct codec_t {
- char name[16];
- char mimetype[32];
- char extension[8];
-
- term_enc_fn_t encode_term;
- gr_encode_init_fn_t encode_graph_init;
- gr_encode_iter_fn_t encode_graph_iter;
- gr_encode_done_fn_t encode_graph_done;
-
- term_decode_fn_t decode_term;
- gr_decode_fn_t decode_graph;
- };
- inline uint8_t
- *uint8_dup (const uint8_t *str)
- { return (uint8_t *) strdup ((char *) str); }
- inline uint8_t
- *uint8_ndup (const uint8_t *str, size_t size)
- { return (uint8_t *) strndup ((char *) str, size); }
- LSUP_rc
- escape_lit (const char *in, char **out);
- static inline char
- escape_char (const char c) {
- switch (c) {
- case '\t': return 't';
- case '\b': return 'b';
- case '\n': return 'n';
- case '\r': return 'r';
- case '\f': return 'f';
- default: return c;
- }
- }
- inline char
- unescape_char (const char c)
- {
- switch (c) {
- case 't': return '\t';
- case 'b': return '\b';
- case 'n': return '\n';
- case 'r': return '\r';
- case 'f': return '\f';
- default: return c;
- }
- }
- uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size);
- char *fmt_header (char *pfx);
- #endif
|