appHand_dataSerialization.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * Copyright (C) 2007-2012 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 Sebastian.Kaebisch.EXT@siemens.com
  20. * @version 0.7
  21. * @contact Joerg.Heuer@siemens.com
  22. *
  23. * <p>Code generated by EXISeGen</p>
  24. *
  25. ********************************************************************/
  26. #include "appHand_service.h"
  27. #include "appHand_dataTypes.h"
  28. #include "EXITypes.h"
  29. #include "StringTable.h"
  30. #include "appHandEXIEncoder.h"
  31. #include "appHandQNameDefines.h"
  32. #include <string.h>
  33. uint16_t numberOfLocalStringsEncode[EXI_appHandMAX_NUMBER_OF_QNAMES];
  34. static int serialize_AppProtocolType(struct AppProtocolType* type, struct EXIDatabinder* service)
  35. {
  36. /* encode start element ProtocolNamespace */
  37. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 2))
  38. {
  39. return -1;
  40. }
  41. service->val.type = EXI_DATATYPE_STRING;
  42. service->val.str.type = EXI_STRING_VALUE_MISS;
  43. service->val.str.miss.len = type->ProtocolNamespace.arraylen.data;
  44. memcpy(service->val.str.miss.codepoints, type->ProtocolNamespace.data,type->ProtocolNamespace.arraylen.data*sizeof(uint32_t));
  45. /* encode character ProtocolNamespace */
  46. if (exiappHandEncodeCharacters(&(service->outStream), &(service->stateEncode), &(service->val)))
  47. {
  48. return -1;
  49. }
  50. /* encode end element of ProtocolNamespace */
  51. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  52. /* encode start element VersionNumberMajor */
  53. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 5))
  54. {
  55. return -1;
  56. }
  57. service->val.type = EXI_DATATYPE_UNSIGNED_INTEGER;
  58. service->val.integer.val.uint32=type->VersionNumberMajor;
  59. service->val.integer.type = EXI_UNSIGNED_INTEGER_32;
  60. /* encode character VersionNumberMajor */
  61. if (exiappHandEncodeCharacters(&(service->outStream), &(service->stateEncode), &(service->val)))
  62. {
  63. return -1;
  64. }
  65. /* encode end element of VersionNumberMajor */
  66. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  67. /* encode start element VersionNumberMinor */
  68. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 6))
  69. {
  70. return -1;
  71. }
  72. service->val.type = EXI_DATATYPE_UNSIGNED_INTEGER;
  73. service->val.integer.val.uint32=type->VersionNumberMinor;
  74. service->val.integer.type = EXI_UNSIGNED_INTEGER_32;
  75. /* encode character VersionNumberMinor */
  76. if (exiappHandEncodeCharacters(&(service->outStream), &(service->stateEncode), &(service->val)))
  77. {
  78. return -1;
  79. }
  80. /* encode end element of VersionNumberMinor */
  81. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  82. /* encode start element SchemaID */
  83. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 4))
  84. {
  85. return -1;
  86. }
  87. service->val.type = EXI_DATATYPE_NBIT_UNSIGNED_INTEGER;
  88. service->val.integer.val.uint8=type->SchemaID;
  89. service->val.integer.type = EXI_UNSIGNED_INTEGER_8;
  90. /* encode character SchemaID */
  91. if (exiappHandEncodeCharacters(&(service->outStream), &(service->stateEncode), &(service->val)))
  92. {
  93. return -1;
  94. }
  95. /* encode end element of SchemaID */
  96. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  97. /* encode start element Priority */
  98. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 1))
  99. {
  100. return -1;
  101. }
  102. service->val.type = EXI_DATATYPE_NBIT_UNSIGNED_INTEGER;
  103. service->val.integer.val.uint8=type->Priority;
  104. service->val.integer.type = EXI_UNSIGNED_INTEGER_8;
  105. /* encode character Priority */
  106. if (exiappHandEncodeCharacters(&(service->outStream), &(service->stateEncode), &(service->val)))
  107. {
  108. return -1;
  109. }
  110. /* encode end element of Priority */
  111. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  112. return 0;
  113. }
  114. static int serialize_AnonType_supportedAppProtocolReq(struct AnonType_supportedAppProtocolReq* type, struct EXIDatabinder* service)
  115. {
  116. size_t i_loop;
  117. for(i_loop=0;i_loop < type->arraylen.AppProtocol;i_loop++)
  118. {
  119. /* encode start element AppProtocol */
  120. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 0))
  121. {
  122. return -1;
  123. }
  124. /* encode children of AppProtocol */
  125. if(serialize_AppProtocolType(&(type->AppProtocol[i_loop]),service))
  126. {
  127. return -1;
  128. }
  129. /* encode end element of AppProtocol */
  130. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  131. }
  132. return 0;
  133. }
  134. static int serialize_AnonType_supportedAppProtocolRes(struct AnonType_supportedAppProtocolRes* type, struct EXIDatabinder* service)
  135. {
  136. /* encode start element ResponseCode */
  137. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 3))
  138. {
  139. return -1;
  140. }
  141. service->val.type = EXI_DATATYPE_ENUMERATION;
  142. service->val.enumeration=type->ResponseCode;
  143. /* encode character ResponseCode */
  144. if (exiappHandEncodeCharacters(&(service->outStream), &(service->stateEncode), &(service->val)))
  145. {
  146. return -1;
  147. }
  148. /* encode end element of ResponseCode */
  149. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  150. if(type->isused.SchemaID)
  151. {
  152. /* encode start element SchemaID */
  153. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 4))
  154. {
  155. return -1;
  156. }
  157. service->val.type = EXI_DATATYPE_NBIT_UNSIGNED_INTEGER;
  158. service->val.integer.val.uint8=type->SchemaID;
  159. service->val.integer.type = EXI_UNSIGNED_INTEGER_8;
  160. /* encode character SchemaID */
  161. if (exiappHandEncodeCharacters(&(service->outStream), &(service->stateEncode), &(service->val)))
  162. {
  163. return -1;
  164. }
  165. /* encode end element of SchemaID */
  166. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  167. }
  168. return 0;
  169. }
  170. static int serialize_EXIDocumentType_appHand(struct EXIDocumentType_appHand* type, struct EXIDatabinder* service)
  171. {
  172. if(type->isused.supportedAppProtocolReq)
  173. {
  174. /* encode start element supportedAppProtocolReq */
  175. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 65))
  176. {
  177. return -1;
  178. }
  179. /* encode children of supportedAppProtocolReq */
  180. if(serialize_AnonType_supportedAppProtocolReq( (type->supportedAppProtocolReq),service))
  181. {
  182. return -1;
  183. }
  184. /* encode end element of supportedAppProtocolReq */
  185. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  186. }
  187. if(type->isused.supportedAppProtocolRes)
  188. {
  189. /* encode start element supportedAppProtocolRes */
  190. if (exiappHandEncodeStartElement(&(service->outStream), &(service->stateEncode), 66))
  191. {
  192. return -1;
  193. }
  194. /* encode children of supportedAppProtocolRes */
  195. if(serialize_AnonType_supportedAppProtocolRes( (type->supportedAppProtocolRes),service))
  196. {
  197. return -1;
  198. }
  199. /* encode end element of supportedAppProtocolRes */
  200. exiappHandEncodeEndElement(&(service->outStream), &(service->stateEncode));
  201. }
  202. return 0;
  203. }
  204. /* serialize data to EXI stream */
  205. static int serialize_message(struct EXIDatabinder* service)
  206. {
  207. /* encode start document */
  208. if (exiappHandEncodeStartDocument(&(service->outStream), &(service->stateEncode)) )
  209. {
  210. return -1;
  211. }
  212. if (serialize_EXIDocumentType_appHand(&(service->exiMsg), service))
  213. {
  214. return -1;
  215. }
  216. /* encode end document */
  217. if (exiappHandEncodeEndDocument(&(service->outStream), &(service->stateEncode))) {
  218. return -1;
  219. }
  220. return 0;
  221. }
  222. int serialize_appHand(struct EXIDatabinder* service, uint8_t* outStream, size_t* payloadLength, struct EXIDocumentType_appHand* exiDoc)
  223. {
  224. exi_name_table_runtime_t runtimeTableEncode;
  225. exi_string_table_t stringTableEncode = { 0, EXI_appHandMAX_NUMBER_OF_QNAMES, numberOfLocalStringsEncode};
  226. uint32_t outPos =service->transportHeaderOffset;
  227. /* assign outStream data to service EXI structure */
  228. service->outStream.data = outStream;
  229. service->outStream.pos = &outPos;
  230. service->outStream.buffer=0;
  231. service->outStream.capacity=8;
  232. service->exiMsg = *exiDoc;
  233. /* init encoder (write header, set initial state) */
  234. exiInitNameTableRuntime(&runtimeTableEncode);
  235. exiappHandInitEncoder(&(service->outStream), &(service->stateEncode), runtimeTableEncode,stringTableEncode);
  236. if(serialize_message(service))
  237. {
  238. return -1;
  239. }
  240. outPos -= service->transportHeaderOffset;
  241. *payloadLength = outPos;
  242. return 0;
  243. }
  244. /* Initialize serializer */
  245. int init_appHandSerializer(struct EXIDatabinder* service, exi_bytes_t service_bytes, exi_string_ucs_t service_string, size_t max_outStream_size, uint16_t transportHeaderOffset)
  246. {
  247. /* init byte array */
  248. service->val.binary = service_bytes;
  249. /* init string array */
  250. service->val.str.miss = service_string;
  251. /* init output stream */
  252. service->outStream.size=max_outStream_size;
  253. service->transportHeaderOffset=transportHeaderOffset;
  254. return 0;
  255. }