codec_base.h 2.6 KB

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