codec_base.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef _LSUP_CODEC_BASE_H
  2. #define _LSUP_CODEC_BASE_H
  3. #include "graph.h"
  4. typedef struct codec_iter_t LSUP_CodecIterator;
  5. /** @brief Term encoder callback type.
  6. *
  7. * @param[in] term Single term handle.
  8. *
  9. * @param[in] nsm Namespace map. May be NULL for no prefix shortening.
  10. *
  11. * @param[out] rep Pointer to a string to be filled with the encoded term. The
  12. * caller is in charge of freeing the string after use. Returns undefined on
  13. * error.
  14. *
  15. * @return LSUP_OK on successful encoding; <0 for other errors.
  16. */
  17. typedef LSUP_rc (*term_enc_fn_t)(
  18. const LSUP_Term *term, const LSUP_NSMap *nsm, char **rep);
  19. /** TODO
  20. */
  21. typedef LSUP_rc (*term_dec_fn_t)(
  22. const char *rep, const LSUP_NSMap *nsm, LSUP_Term **term);
  23. /** @brief Graph encoder callback type.
  24. *
  25. * @return LSUP_OK on successful encoding; <0 for other errors.
  26. */
  27. typedef LSUP_CodecIterator * (*gr_codec_init_fn_t)(const LSUP_Graph *gr);
  28. typedef LSUP_rc (*gr_codec_iter_fn_t)(LSUP_CodecIterator *it);
  29. typedef void (*gr_codec_done_fn_t)(LSUP_CodecIterator *it);
  30. /** TODO
  31. */
  32. typedef LSUP_rc (*gr_dec_fn_t)(const char *rep, LSUP_Graph **gr);
  33. /** @brief Codec structure.
  34. *
  35. * An instance of this structure is usually defined at compile time (see
  36. * examples in "include/codec_*.h" and "src/codec_*.c") and should have the
  37. * following defined:
  38. *
  39. * - name: A brief (16-char max), human-readable to identify the codec.
  40. * - mimetype: MIME type associated with the codec.
  41. * - extension: File extension associated with the serialized file.
  42. * - term_encoder: Callback function for encoding a single term.
  43. * - term_decoder: Callback function for decoding a single term.
  44. *
  45. * There is no validation enforced, but at least the name, mimetype and
  46. * extension, as well as one or more encoding functions and their respective
  47. * decoding functions, should be defined in a codec.
  48. */
  49. typedef struct codec_t {
  50. char name[16]; // Name of the codec.
  51. char mimetype[32]; // MIME type associated with the codec.
  52. char extension[8]; // Serialized file extension.
  53. // Term encoding and decoding.
  54. term_enc_fn_t term_encoder; // Term encoder function.
  55. term_dec_fn_t term_decoder; // Term decoder function.
  56. // Graph encoding.
  57. gr_codec_init_fn_t gr_encode_init; // Graph encoder initialization.
  58. gr_codec_iter_fn_t gr_encode_iter; // Graph encoder initialization.
  59. gr_codec_done_fn_t gr_encode_done; // Graph encoder initialization.
  60. // Graph decoding.
  61. gr_codec_init_fn_t gr_decode_init; // Graph decoder initialization.
  62. gr_codec_iter_fn_t gr_decode_iter; // Graph decoder initialization.
  63. gr_codec_done_fn_t gr_decode_done; // Graph decoder initialization.
  64. } LSUP_Codec;
  65. #endif