#ifndef _LSUP_CODEC_BASE_H #define _LSUP_CODEC_BASE_H #include "graph.h" typedef struct codec_iter_t LSUP_CodecIterator; /** @brief Term encoder callback type. * * @param[in] term Single term handle. * * @param[in] nsm Namespace map. May be NULL for no prefix shortening. * * @param[out] rep Pointer to a string to be filled with the encoded term. The * caller is in charge of freeing the string after use. Returns undefined on * error. * * @return LSUP_OK on successful encoding; <0 for other errors. */ typedef LSUP_rc (*term_enc_fn_t)( const LSUP_Term *term, const LSUP_NSMap *nsm, char **rep); /** TODO */ typedef LSUP_rc (*term_dec_fn_t)( const char *rep, const LSUP_NSMap *nsm, LSUP_Term **term); /** @brief Graph encoder callback type. * * @return LSUP_OK on successful encoding; <0 for other errors. */ typedef LSUP_CodecIterator * (*gr_codec_init_fn_t)(const LSUP_Graph *gr); typedef LSUP_rc (*gr_codec_iter_fn_t)(LSUP_CodecIterator *it); typedef void (*gr_codec_done_fn_t)(LSUP_CodecIterator *it); /** TODO */ typedef LSUP_rc (*gr_dec_fn_t)(const char *rep, LSUP_Graph **gr); /** @brief Codec structure. * * An instance of this structure is usually defined at compile time (see * examples in "include/codec_*.h" and "src/codec_*.c") and should have the * following defined: * * - name: A brief (16-char max), human-readable to identify the codec. * - mimetype: MIME type associated with the codec. * - extension: File extension associated with the serialized file. * - term_encoder: Callback function for encoding a single term. * - term_decoder: Callback function for decoding a single term. * * There is no validation enforced, but at least the name, mimetype and * extension, as well as one or more encoding functions and their respective * decoding functions, should be defined in a codec. */ typedef struct codec_t { char name[16]; // Name of the codec. char mimetype[32]; // MIME type associated with the codec. char extension[8]; // Serialized file extension. // Term encoding and decoding. term_enc_fn_t term_encoder; // Term encoder function. term_dec_fn_t term_decoder; // Term decoder function. // Graph encoding. gr_codec_init_fn_t gr_encode_init; // Graph encoder initialization. gr_codec_iter_fn_t gr_encode_iter; // Graph encoder initialization. gr_codec_done_fn_t gr_encode_done; // Graph encoder initialization. // Graph decoding. gr_codec_init_fn_t gr_decode_init; // Graph decoder initialization. gr_codec_iter_fn_t gr_decode_iter; // Graph decoder initialization. gr_codec_done_fn_t gr_decode_done; // Graph decoder initialization. } LSUP_Codec; #endif