You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.7KB

  1. #ifndef _ebml_h_
  2. #define _ebml_h_
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. enum ebml_element_type_t
  9. {
  10. EBML_TYPE_UNKNOWN,
  11. EBML_TYPE_INT, // Signed Integer Element [0-8]
  12. EBML_TYPE_UINT, // Unsigned Integer Element [0-8]
  13. EBML_TYPE_FLOAT, // Float Element (0/4/8)
  14. EBML_TYPE_STRING, // ASCII String Element [0-VINTMAX]
  15. EBML_TYPE_UTF8, // UTF-8 Element [0-VINTMAX]
  16. EBML_TYPE_DATE, // Date Element [0-8]
  17. EBML_TYPE_MASTER, // Master Element [0-VINTMAX]
  18. EBML_TYPE_BINARY, // Binary Element [0-VINTMAX]
  19. };
  20. struct ebml_t
  21. {
  22. uint8_t* ptr;
  23. size_t off;
  24. size_t len;
  25. int err;
  26. };
  27. // https://github.com/ietf-wg-cellar/ebml-specification/blob/master/specification.markdown#ebml-header-elements
  28. struct ebml_header_t
  29. {
  30. unsigned int version; // default 1
  31. unsigned int read_version; // default 1
  32. unsigned int max_id_length; // default 4
  33. unsigned int max_size_length; // default 8
  34. char* doc_type;
  35. unsigned int doc_type_version; // default 1
  36. unsigned int doc_type_read_version; // default 1
  37. };
  38. /// @return size with prefix bytes
  39. unsigned int ebml_size_length(uint64_t size);
  40. /// @return unsigned integer value bytes
  41. unsigned int ebml_uint_length(uint64_t v);
  42. /// @param[out] buf value writer buffer
  43. /// @return value length (same as ebml_uint_length)
  44. unsigned int ebml_write_uint(uint8_t buf[8], uint64_t v);
  45. /// Write EBML element id + size
  46. /// @param[out] buf write buffer
  47. /// @param[in] id element id
  48. /// @param[in] size element size
  49. /// @param[in] bytes size write bytes, 0-ebml_size_length(size)
  50. /// @return write length
  51. unsigned int ebml_write_element(uint8_t buf[12], uint32_t id, uint64_t size, unsigned int bytes);
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif /* !_ebml_h_ */