EXITypes.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (C) 2007-2010 Siemens AG
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published
  6. * by the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*******************************************************************
  18. *
  19. * @author Daniel.Peintner.EXT@siemens.com
  20. * @version 0.1
  21. * @contact Joerg.Heuer@siemens.com
  22. *
  23. ********************************************************************/
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <string.h>
  28. #include <stdint.h>
  29. #ifndef EXI_TYPES_H
  30. #define EXI_TYPES_H
  31. #define BITS_IN_BYTE 8
  32. #define EXI_ELEMENT_STACK_SIZE 16
  33. /* EXI automaton methods prefixes such as "inline" etc. */
  34. #ifndef EXI_MPFX
  35. #define EXI_MPFX
  36. #endif
  37. #define FLOAT_EXPONENT_SPECIAL_VALUES -16384
  38. #define FLOAT_MANTISSA_INFINITY 1
  39. #define FLOAT_MANTISSA_MINUS_INFINITY -1
  40. #define FLOAT_MANTISSA_NOT_A_NUMBER 0
  41. typedef struct {
  42. /* Integer Array */
  43. size_t size; /* array size */
  44. uint8_t* data; /* int data array */
  45. size_t* pos; /* next position in array */
  46. /* Current byte buffer & its remaining bit capacity */
  47. uint8_t buffer;
  48. size_t capacity;
  49. } bitstream_t;
  50. typedef struct {
  51. /* Bytes Size and array container */
  52. size_t size;
  53. uint8_t* data;
  54. /* current length (len <= size) */
  55. size_t len;
  56. } bytes_t;
  57. /* Universal Character Set (UCS) strings */
  58. typedef struct {
  59. /* UCS size and UCS character container*/
  60. size_t size;
  61. uint32_t* codepoints;
  62. /* current length == number of code-points, (len <= size) */
  63. size_t len;
  64. } string_ucs_t;
  65. /* ASCII strings */
  66. typedef struct {
  67. size_t size;
  68. char* ascii;
  69. /* current length == number of characters, (len <= size) */
  70. size_t len;
  71. } string_ascii_t;
  72. typedef struct {
  73. /* range of the mantissa is -(2^63) to 2^63-1 */
  74. int64_t mantissa;
  75. /* range of the exponent is - (2^14-1) to 2^14-1 */
  76. int32_t exponent; /* base-10 */
  77. } float_me_t;
  78. typedef enum
  79. {
  80. /* Binary */
  81. BINARY_BASE64, BINARY_HEX,
  82. /* Boolean */
  83. BOOLEAN,
  84. /* Decimal */
  85. DECIMAL,
  86. /* Float */
  87. FLOAT, DOUBLE,
  88. /* N-Bit Integer */
  89. NBIT_INTEGER_32, NBIT_INTEGER_64, NBIT_INTEGER_BIG,
  90. /* Unsigned Integer */
  91. UNSIGNED_INTEGER_16, UNSIGNED_INTEGER_32, UNSIGNED_INTEGER_64, UNSIGNED_INTEGER_BIG,
  92. /* (Signed) Integer */
  93. INTEGER_16, INTEGER_32, INTEGER_64, INTEGER_BIG,
  94. /* Datetime */
  95. DATETIME,
  96. /* String */
  97. STRING,
  98. /* Enumeration */
  99. ENUMERATION,
  100. /* List */
  101. LIST
  102. } exi_datatype_t;
  103. typedef enum
  104. {
  105. START_DOCUMENT,
  106. END_DOCUMENT,
  107. START_ELEMENT,
  108. START_ELEMENT_GENERIC, /* not supported yet */
  109. END_ELEMENT,
  110. CHARACTERS,
  111. CHARACTERS_GENERIC, /* not supported yet */
  112. ATTRIBUTE,
  113. ATTRIBUTE_GENERIC, /* not supported yet */
  114. /* error state */
  115. ERROR
  116. } exi_event_t;
  117. /* TODO list support */
  118. typedef struct {
  119. /* List container with memory size */
  120. size_t size;
  121. uint8_t* data;
  122. /* list item type */
  123. exi_datatype_t type;
  124. /* number of items */
  125. size_t len;
  126. } list_t;
  127. typedef struct {
  128. unsigned int namespaceURI;
  129. unsigned int localPart;
  130. } eqname_t;
  131. typedef struct {
  132. /* stack of grammar states and elements */
  133. size_t grammarStack [EXI_ELEMENT_STACK_SIZE];
  134. eqname_t elementStack [EXI_ELEMENT_STACK_SIZE];
  135. size_t stackIndex;
  136. /* event-code */
  137. uint8_t eventCode;
  138. } exi_state_t;
  139. typedef struct {
  140. /* union of base types */
  141. union {
  142. int boolean;
  143. int8_t int8;
  144. uint8_t uint8;
  145. uint32_t uint32;
  146. int32_t int32;
  147. int64_t int64;
  148. uint8_t enumeration;
  149. };
  150. /* Bytes, Strings and Lists are not base types */
  151. bytes_t binary;
  152. string_ucs_t string;
  153. list_t list;
  154. /* value datatype */
  155. exi_datatype_t type;
  156. } exi_value_t;
  157. /*
  158. * ERROR-Codes
  159. */
  160. # define EXI_ERROR_OUT_OF_BOUNDS -100
  161. # define EXI_ERROR_UNKOWN_EVENT_CODE -110
  162. #endif
  163. #ifdef __cplusplus
  164. }
  165. #endif