EXITypes.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. * Copyright (C) 2007-2018 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 2017-03-02
  21. * @contact Richard.Kuntschke@siemens.com
  22. *
  23. * <p>Code generated by EXIdizer</p>
  24. * <p>Schema: V2G_CI_MsgDef.xsd</p>
  25. *
  26. *
  27. ********************************************************************/
  28. /**
  29. * \file EXITypes.h
  30. * \brief Basic type definitions and structs
  31. *
  32. */
  33. #ifndef EXI_TYPES_H
  34. #define EXI_TYPES_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. #include <stdint.h>
  39. #include <stdio.h>
  40. #include "EXIConfig.h"
  41. #if EXI_STREAM == FILE_STREAM
  42. #include <stdio.h>
  43. #endif
  44. /** Number of bits for each byte */
  45. #define BITS_IN_BYTE 8
  46. /** EXI Date-Time offset for year */
  47. #define DATETIME_YEAR_OFFSET 2000
  48. /** EXI Date-Time number of bits for monthDay */
  49. #define DATETIME_NUMBER_BITS_MONTHDAY 9
  50. /** EXI Date-Time number of bits for time */
  51. #define DATETIME_NUMBER_BITS_TIME 17
  52. /** EXI Date-Time number of bits for timezone */
  53. #define DATETIME_NUMBER_BITS_TIMEZONE 11
  54. /** EXI Date-Time month multiplicator */
  55. #define DATETIME_MONTH_MULTIPLICATOR 32
  56. /** EXI Date-Time offset for timzone minutes */
  57. #define DATETIME_TIMEZONE_OFFSET_IN_MINUTES 896
  58. /** Maximum integer value for uint */
  59. #define UINT_MAX_VALUE 65535
  60. /** EXI Float exponent special values */
  61. #define FLOAT_EXPONENT_SPECIAL_VALUES -16384
  62. /** EXI Float mantissa infinity */
  63. #define FLOAT_MANTISSA_INFINITY 1
  64. /** EXI Float minus mantissa infinity */
  65. #define FLOAT_MANTISSA_MINUS_INFINITY -1
  66. /** EXI Float not a number */
  67. #define FLOAT_MANTISSA_NOT_A_NUMBER 0
  68. /** \brief EXI Events */
  69. typedef enum {
  70. /** Start Document SD */
  71. EXI_EVENT_START_DOCUMENT,
  72. /** End Document ED */
  73. EXI_EVENT_END_DOCUMENT,
  74. /** Start Element SE(qname) */
  75. EXI_EVENT_START_ELEMENT,
  76. /** Start Element SE(uri:*) */
  77. EXI_EVENT_START_ELEMENT_NS,
  78. /** Start Element SE(*) generic */
  79. EXI_EVENT_START_ELEMENT_GENERIC,
  80. /** Start Element SE(*) generic undeclared */
  81. EXI_EVENT_START_ELEMENT_GENERIC_UNDECLARED,
  82. /** End Element EE */
  83. EXI_EVENT_END_ELEMENT,
  84. /** End Element EE undeclared*/
  85. EXI_EVENT_END_ELEMENT_UNDECLARED,
  86. /** Characters CH */
  87. EXI_EVENT_CHARACTERS,
  88. /** Characters CH generic */
  89. EXI_EVENT_CHARACTERS_GENERIC,
  90. /** Characters CH generic undeclared */
  91. EXI_EVENT_CHARACTERS_GENERIC_UNDECLARED,
  92. /** Attribute AT(xsi:type) */
  93. EXI_EVENT_ATTRIBUTE_XSI_TYPE,
  94. /** Attribute AT(xsi:nil) */
  95. EXI_EVENT_ATTRIBUTE_XSI_NIL,
  96. /** Attribute AT(qname) */
  97. EXI_EVENT_ATTRIBUTE,
  98. /** Attribute AT(uri:*) */
  99. EXI_EVENT_ATTRIBUTE_NS,
  100. /** Attribute AT(*) generic */
  101. EXI_EVENT_ATTRIBUTE_GENERIC,
  102. /** Attribute AT(*) invalid value */
  103. EXI_EVENT_ATTRIBUTE_INVALID_VALUE,
  104. /** Attribute AT(*) any invalid value */
  105. EXI_EVENT_ATTRIBUTE_ANY_INVALID_VALUE,
  106. /** Attribute AT(*) generic undeclared */
  107. EXI_EVENT_ATTRIBUTE_GENERIC_UNDECLARED,
  108. /* error state */
  109. EXI_EVENT_ERROR
  110. } exi_event_t;
  111. /**
  112. * \brief Bit stream container
  113. *
  114. * Structure for byteArray/file stream.
  115. *
  116. * # General
  117. * .size defines the maximum size of the byte array (see .data)
  118. *
  119. * .data points to the input/output array of bytes (unsigned char*).
  120. *
  121. * .pos has to be set to an pointer to an 32 bit long unsigned integer (uint32_t *)
  122. * as this variable is read/write.
  123. * Therefore it is best practice to declare the variable itself and use the &-operator
  124. * to assign the address. The value of that variable points to the position inside the
  125. * buffer where the stream begins. Which is usually the first (0th) byte but can also be
  126. * another value if there more information transferred in that stream.
  127. * After processing .pos points to the next "available" byte (if any left).
  128. *
  129. * .buffer has to be set to 0 for internal use only (single byte buffer)
  130. *
  131. * # Receiving data (input)
  132. * .capacity is used for addressing single bits in the actual byte (see .buffer)
  133. * and has to be set to 0, which means there are 0 bits read so far and a new
  134. * byte needs to be read from the input stream/data-array to the current byte buffer.
  135. *
  136. * # Sending data (output)
  137. * .capacity is used for addressing single bits in the actual byte (see .buffer)
  138. * and has to be set to 8, which means there are still 8 bits left to fill up
  139. * the current byte buffer before writing the final byte to the output stream/data-array.
  140. *
  141. */
  142. typedef struct {
  143. #if EXI_STREAM == BYTE_ARRAY
  144. /** byte array size */
  145. size_t size;
  146. /** byte array data */
  147. uint8_t* data;
  148. /** byte array next position in array */
  149. size_t* pos;
  150. #endif
  151. #if EXI_STREAM == FILE_STREAM
  152. /** file pointer */
  153. FILE *file;
  154. #endif
  155. /** Current byte buffer*/
  156. uint8_t buffer;
  157. /** Remaining bit capacity in current byte buffer*/
  158. uint8_t capacity;
  159. } bitstream_t;
  160. /** \brief EXI Value Datatypes */
  161. typedef enum {
  162. /** Binary Base64 */
  163. EXI_DATATYPE_BINARY_BASE64,
  164. /** Binary Hex */
  165. EXI_DATATYPE_BINARY_HEX,
  166. /** Boolean */
  167. EXI_DATATYPE_BOOLEAN,
  168. /** Boolean with Facets */
  169. EXI_DATATYPE_BOOLEAN_FACET,
  170. /** Decimal */
  171. EXI_DATATYPE_DECIMAL,
  172. /** Float & Double */
  173. EXI_DATATYPE_FLOAT,
  174. /** N-Bit Unsigned Integer */
  175. EXI_DATATYPE_NBIT_UNSIGNED_INTEGER,
  176. /** Unsigned Integer */
  177. EXI_DATATYPE_UNSIGNED_INTEGER,
  178. /** (Signed) Integer */
  179. EXI_DATATYPE_INTEGER,
  180. /** Datetime */
  181. EXI_DATATYPE_DATETIME,
  182. /** String */
  183. EXI_DATATYPE_STRING,
  184. /** Restricted Character Set String */
  185. EXI_DATATYPE_RCS_STRING,
  186. /** Enumeration */
  187. EXI_DATATYPE_ENUMERATION,
  188. /** List */
  189. EXI_DATATYPE_LIST,
  190. /** QName (e.g. xsi:type) */
  191. EXI_DATATYPE_QNAME
  192. } exi_datatype_t;
  193. /** \brief EXI Integer Value types */
  194. typedef enum {
  195. /** Unsigned Integer 8 bits */
  196. EXI_UNSIGNED_INTEGER_8,
  197. /** Unsigned Integer 16 bits */
  198. EXI_UNSIGNED_INTEGER_16,
  199. /** Unsigned Integer 32 bits */
  200. EXI_UNSIGNED_INTEGER_32,
  201. /** Unsigned Integer 64 bits */
  202. EXI_UNSIGNED_INTEGER_64,
  203. /** (Signed) Integer 8 bits */
  204. EXI_INTEGER_8,
  205. /** (Signed) Integer 16 bits */
  206. EXI_INTEGER_16,
  207. /** (Signed) Integer 32 bits */
  208. EXI_INTEGER_32,
  209. /** (Signed) Integer 64 bits */
  210. EXI_INTEGER_64
  211. } exi_integer_type_t;
  212. /** \brief EXI Datetime types */
  213. typedef enum {
  214. /** gYear */
  215. EXI_DATETIME_GYEAR,
  216. /** gYearMonth */
  217. EXI_DATETIME_GYEARMONTH,
  218. /** date */
  219. EXI_DATETIME_DATE,
  220. /** datetime */
  221. EXI_DATETIME_DATETIME,
  222. /** gMonth */
  223. EXI_DATETIME_GMONTH,
  224. /** gMonthDay */
  225. EXI_DATETIME_GMONTHDAY,
  226. /** gDay */
  227. EXI_DATETIME_GDAY,
  228. /** time */
  229. EXI_DATETIME_TIME
  230. } exi_datetime_type_t;
  231. /** \brief String value type */
  232. typedef enum {
  233. /** value miss */
  234. EXI_STRING_VALUE_MISS,
  235. /** value local-hit */
  236. EXI_STRING_VALUE_LOCAL_HIT,
  237. /** value global-hit */
  238. EXI_STRING_VALUE_GLOBAL_HIT
  239. } exi_string_value_type_t;
  240. /** \brief EXI string character */
  241. /* Note: define whether you wan't to support ASCII only or UCS */
  242. #if STRING_REPRESENTATION == STRING_REPRESENTATION_ASCII
  243. typedef char exi_string_character_t;
  244. #endif /* STRING_REPRESENTATION_ASCII */
  245. #if STRING_REPRESENTATION == STRING_REPRESENTATION_UCS
  246. typedef uint32_t exi_string_character_t;
  247. #endif /* STRING_REPRESENTATION_UCS */
  248. /** \brief Universal Character Set (UCS) strings */
  249. typedef struct {
  250. /** container size */
  251. size_t size;
  252. /** string character container */
  253. exi_string_character_t* characters;
  254. /** current string length == number of code-points, (len <= size) */
  255. size_t len;
  256. } exi_string_t;
  257. /** \brief String value */
  258. typedef struct {
  259. /** value type (e.g., miss, local-hit, global-hit) */
  260. exi_string_value_type_t type;
  261. /** miss entry */
  262. exi_string_t miss;
  263. /** (local) hit entry */
  264. size_t localID;
  265. /** (global) hit entry */
  266. size_t globalID;
  267. } exi_string_value_t;
  268. /** \brief Restricted Characeter Set */
  269. typedef struct {
  270. /** size */
  271. size_t size;
  272. /** rcs codepoints */
  273. exi_string_character_t* characters;
  274. /** character coding length (less than 256 characters) */
  275. uint8_t codingLength;
  276. } exi_rcs_t;
  277. /** \brief Byte value container */
  278. typedef struct {
  279. /** bytes array size */
  280. size_t size;
  281. /** bytes array data container */
  282. uint8_t* data;
  283. /** bytes array length (len <= size) */
  284. size_t len;
  285. } exi_bytes_t;
  286. /** \brief Integer value container */
  287. typedef struct {
  288. /** type */
  289. exi_integer_type_t type;
  290. union {
  291. /* (signed) values */
  292. /** (signed) int 8 bits */
  293. int8_t int8;
  294. /** (signed) int 16 bits */
  295. int16_t int16;
  296. /** (signed) int 32 bits */
  297. int32_t int32;
  298. /** (signed) int 64 bits */
  299. int64_t int64;
  300. /* unsigned values */
  301. /** unsigned int 8 bits */
  302. uint8_t uint8;
  303. /** unsigned int 16 bits */
  304. uint16_t uint16;
  305. /** unsigned int 32 bits */
  306. uint32_t uint32;
  307. /** unsigned int 64 bits */
  308. uint64_t uint64;
  309. } val;
  310. } exi_integer_t;
  311. /** \brief Float value container */
  312. typedef struct {
  313. /** range of the mantissa is -(2^63) to 2^63-1 */
  314. int64_t mantissa;
  315. /** range of the exponent is - (2^14-1) to 2^14-1 */
  316. int16_t exponent; /* base-10 */
  317. } exi_float_me_t;
  318. /** \brief Decimal value container */
  319. typedef struct {
  320. /** a sign value */
  321. int negative;
  322. /** represents the integral portion of the Decimal */
  323. exi_integer_t integral;
  324. /** represents the fractional portion of the Decimal with the digits in reverse order to preserve leading zeros */
  325. exi_integer_t reverseFraction;
  326. } exi_decimal_t;
  327. /** \brief Datetime value container */
  328. typedef struct {
  329. /** datetime type */
  330. exi_datetime_type_t type;
  331. /** Datetime value for year */
  332. int32_t year;
  333. /** Datetime value for monthDay */
  334. uint32_t monthDay;
  335. /** Datetime value for time */
  336. uint32_t time;
  337. /** Datetime value for presenceFractionalSecs */
  338. int presenceFractionalSecs;
  339. /** Datetime value for fractionalSecs */
  340. uint32_t fractionalSecs;
  341. /** Datetime value for presenceTimezone */
  342. int presenceTimezone;
  343. /** Datetime value for timezone */
  344. uint32_t timezone;
  345. } exi_datetime_t;
  346. /** \brief List value container */
  347. typedef struct {
  348. /** list item type */
  349. exi_datatype_t type;
  350. /** number of items */
  351. size_t len;
  352. /* Special datatype: integer */
  353. /* exi_integer_type_t intType;*/
  354. /** Special datatype: datetime */
  355. exi_datetime_type_t datetimeType;
  356. } exi_list_t;
  357. /** \brief Efficient qname */
  358. typedef struct {
  359. /** namespace URI ID*/
  360. size_t namespaceURI;
  361. /** local name ID*/
  362. size_t localPart;
  363. } exi_eqname_t;
  364. /** \brief Name entry type */
  365. typedef enum {
  366. /** As known IDs */
  367. EXI_NAME_ENTRY_TYPE_ID,
  368. /** As String */
  369. EXI_NAME_ENTRY_TYPE_STRING_AND_ID
  370. } exi_name_entry_type_t;
  371. /** \brief Name entry */
  372. typedef struct {
  373. /** type */
  374. exi_name_entry_type_t type;
  375. /** entry ID */
  376. size_t id;
  377. /** entry string */
  378. exi_string_t str;
  379. } exi_name_entry_t;
  380. /** \brief Qualified name */
  381. typedef struct {
  382. /** Uri */
  383. exi_name_entry_t uri;
  384. /** LocalName */
  385. exi_name_entry_t localName;
  386. } exi_qname_t;
  387. /*TODO Doxygen Documentation */
  388. /* ==================================== */
  389. /* URI and LocalName Entries */
  390. typedef struct exiNameTablePrepopulated {
  391. /* number of namespaces AND length name-partitions array */
  392. size_t len;
  393. /* number of localName entries divided by URI */
  394. size_t* localNames;
  395. } exi_name_table_prepopulated_t;
  396. #define EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_ENTRIES 25
  397. typedef enum {
  398. EXI_NAME_PARTITION_URI, EXI_NAME_PARTITION_LOCALNAME
  399. } exi_name_partition_type_t;
  400. typedef struct {
  401. char* uri;
  402. size_t uriID;
  403. } exi_uri_partition_t;
  404. typedef struct {
  405. char* localName;
  406. size_t localNameID;
  407. size_t uriID;
  408. } exi_localname_partition_t;
  409. typedef struct {
  410. exi_name_partition_type_t namePartitionType;
  411. struct {
  412. exi_uri_partition_t uriPartition;
  413. exi_localname_partition_t localNamePartition;
  414. } entry;
  415. } exi_name_partition_t;
  416. typedef struct exiNameTableRuntime {
  417. /* maximum number of characters in the name partitions entries PLUS null terminators */
  418. /* char characters[EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_CHARACTERS + EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_ENTRIES]; */
  419. /* uint16_t numberOfUsedCharacters; *//* initially zero <= EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_CHARACTERS */
  420. /* maximum number of name partitions entries. Name partitions entries consist in all uri, and local-name partition entries */
  421. exi_name_partition_t
  422. namePartitionsEntries[EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_ENTRIES];
  423. /* uint16_t numberOfUsedNamePartitions; *//* initially zero */
  424. /* added entries */
  425. size_t addedUriEntries; /* initially zero */
  426. size_t addedLocalNameEntries; /* initially zero */
  427. } exi_name_table_runtime_t;
  428. /* StartTagContent grammar initially empty */
  429. /* ElementContent grammar has EE per default */
  430. typedef struct {
  431. size_t namespaceUriID;
  432. size_t localNameID;
  433. size_t numberOfProductions;
  434. int hasXsiType; /* StartTagContent only */
  435. int hasEE; /* ElementContentper default TRUE */
  436. } exi_runtime_element_t;
  437. /* Note: We do have twice as many runtime grammars (StartTagContent and ElementContent)*/
  438. #define MAX_NUMBER_OF_RUNTIME_ELEMENTS 80
  439. /* ==================================== */
  440. /* Value string table */
  441. typedef struct exiValueStringTableEntry {
  442. /** Qualified namespace URI */
  443. size_t namespaceUriID;
  444. /** Qualified localName */
  445. size_t localNameID;
  446. /** Local Value ID */
  447. size_t localValueID;
  448. /** String */
  449. exi_string_t str;
  450. } exi_value_string_table_entry_t;
  451. typedef struct exiValueStringTable {
  452. /** maximum number of global string table entry size */
  453. size_t size;
  454. /** string table entry array container */
  455. exi_value_string_table_entry_t* strs;
  456. /** current number of string table entries (len <= size) */
  457. size_t len;
  458. } exi_value_string_table_t;
  459. /* typedef struct { */
  460. /** number of global strings */
  461. /* uint16_t numberOfGlobalStrings; */
  462. /** size of local-names container */
  463. /* uint16_t sizeLocalStrings; */
  464. /** number of local strings container */
  465. /* uint16_t* numberOfLocalStrings; */
  466. /** string values */
  467. /* exi_value_string_table_t* valueStringTable;
  468. } exi_value_table_t;*/
  469. typedef struct {
  470. /** stack of grammar states */
  471. int16_t grammarStack[EXI_ELEMENT_STACK_SIZE];
  472. /** stack of grammar elements / qnameIDs */
  473. exi_eqname_t elementStack[EXI_ELEMENT_STACK_SIZE];
  474. /** stack index for both stacks */
  475. size_t stackIndex;
  476. /** event-code */
  477. uint32_t eventCode;
  478. /** name table entries, pre-populated */
  479. exi_name_table_prepopulated_t* nameTablePrepopulated;
  480. /** name table entries, at runtime */
  481. exi_name_table_runtime_t* nameTableRuntime;
  482. /** next qname ID */
  483. size_t nextQNameID;
  484. /** string table entries */
  485. exi_value_string_table_t* stringTable;
  486. /** runtime built-in element grammars - numbers */
  487. size_t numberOfRuntimeGrammars;
  488. /** runtime built-in element grammars */
  489. exi_runtime_element_t runtimeGrammars[MAX_NUMBER_OF_RUNTIME_ELEMENTS * 2];
  490. } exi_state_t;
  491. typedef struct {
  492. /* type of value */
  493. exi_datatype_t type;
  494. /* base types */
  495. int boolean;
  496. uint32_t enumeration;
  497. /* complex types: Integers, Bytes, Strings and Lists are not native types anymore */
  498. exi_integer_t integer;
  499. exi_bytes_t binary;
  500. exi_string_value_t str;
  501. exi_float_me_t float_me;
  502. exi_decimal_t decimal;
  503. exi_datetime_t datetime;
  504. exi_list_t list;
  505. exi_eqname_t eqname;
  506. } exi_value_t;
  507. #ifdef __cplusplus
  508. }
  509. #endif
  510. #endif