1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #ifndef _LSUP_CODEC_BASE_H
- #define _LSUP_CODEC_BASE_H
- #include "graph.h"
- /** @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 Triple encoder callback type.
- *
- * @return LSUP_OK on successful encoding; <0 for other errors.
- */
- typedef LSUP_rc (*trp_enc_fn_t)(
- const LSUP_Triple trp[], const LSUP_NSMap *nsm, char **rep);
- /** TODO
- */
- typedef LSUP_rc (*trp_dec_fn_t)(
- const char *rep, const LSUP_NSMap *nsm, LSUP_Triple **trp);
- /** @brief Graph encoder callback type.
- *
- * @return LSUP_OK on successful encoding; <0 for other errors.
- */
- typedef LSUP_rc (*gr_enc_fn_t)(const LSUP_Graph *gr, char **rep);
- /** 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_enc_fn_t term_encoder; // Term encoder function.
- term_dec_fn_t term_decoder; // Term decoder function.
- trp_enc_fn_t trp_encoder; // Triple encoder function.
- trp_dec_fn_t trp_decoder; // Triple decoder function.
- gr_enc_fn_t gr_encoder; // Graph encoder function.
- gr_dec_fn_t gr_decoder; // Graph decoder function.
- } LSUP_Codec;
- #endif
|