codec_base.h 3.3 KB

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