container.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * ESG parser
  3. *
  4. * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #ifndef _ESG_ENCAPSULATION_CONTAINER_H
  21. #define _ESG_ENCAPSULATION_CONTAINER_H 1
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. #include <stdint.h>
  27. /**
  28. * esg_container_structure structure.
  29. */
  30. struct esg_container_structure {
  31. uint8_t type;
  32. uint8_t id;
  33. uint32_t ptr;
  34. uint32_t length;
  35. void *data;
  36. struct esg_container_structure *_next;
  37. };
  38. /**
  39. * esg_container_header structure.
  40. */
  41. struct esg_container_header {
  42. uint8_t num_structures;
  43. struct esg_container_structure *structure_list;
  44. };
  45. /**
  46. * esg_container structure
  47. */
  48. struct esg_container {
  49. struct esg_container_header *header;
  50. uint32_t structure_body_ptr;
  51. uint32_t structure_body_length;
  52. uint8_t *structure_body;
  53. };
  54. /**
  55. * Process an esg_container.
  56. *
  57. * @param buffer Binary buffer to decode.
  58. * @param size Binary buffer size.
  59. * @return Pointer to an esg_container structure, or NULL on error.
  60. */
  61. extern struct esg_container *esg_container_decode(uint8_t *buffer, uint32_t size);
  62. /**
  63. * Free an esg_container.
  64. *
  65. * @param container Pointer to an esg_container structure.
  66. */
  67. extern void esg_container_free(struct esg_container *container);
  68. /**
  69. * Convenience iterator for structure_list field of an esg_container_header.
  70. *
  71. * @param container The esg_container_header pointer.
  72. * @param structure Variable holding a pointer to the current esg_container_structure.
  73. */
  74. #define esg_container_header_structure_list_for_each(header, structure) \
  75. for ((structure) = (header)->structure_list; \
  76. (structure); \
  77. (structure) = (structure)->_next)
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif