appHand_DataSerialization.c 11 KB

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