opcua_binaryEncDec.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. /*
  2. * opcua_binaryEncDec.c
  3. *
  4. * Created on: Dec 18, 2013
  5. * Author: opcua
  6. */
  7. #include "opcua_binaryEncDec.h"
  8. #include "opcua_types.h"
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "opcua_builtInDatatypes.h"
  12. #include "opcua_advancedDatatypes.h"
  13. Int32 encoder_encodeBuiltInDatatype(void *data, Int32 type, Int32 *pos,
  14. char *dstBuf) {
  15. switch (type) {
  16. case BOOLEAN:
  17. encodeBoolean((*(Boolean*) data), pos, dstBuf);
  18. break;
  19. case SBYTE:
  20. encodeSByte((*(Byte*) data), pos, dstBuf);
  21. break;
  22. case BYTE:
  23. encodeByte((*(Byte*) data), pos, dstBuf);
  24. break;
  25. case INT16:
  26. encodeInt16((*(Int16*) data), pos, dstBuf);
  27. break;
  28. case UINT16:
  29. encodeUInt16((*(UInt16*) data), pos, dstBuf);
  30. break;
  31. case INT32:
  32. encodeInt32((*(Int32*) data), pos, dstBuf);
  33. break;
  34. case UINT32:
  35. encodeUInt32(*(UInt32*) (data), pos, dstBuf);
  36. break;
  37. case INT64:
  38. encodeInt64((*(Int64*) data), pos, dstBuf);
  39. break;
  40. case UINT64:
  41. encodeUInt64((*(UInt64*) data), pos, dstBuf);
  42. break;
  43. case FLOAT:
  44. encodeFloat((*(Float*) data), pos, dstBuf);
  45. break;
  46. case DOUBLE:
  47. encodeDouble((*(Double*) data), pos, dstBuf);
  48. break;
  49. case STRING:
  50. encodeUAString(((UA_String*) data), pos, dstBuf);
  51. break;
  52. case DATE_TIME:
  53. encodeUADateTime((*(UA_DateTime*) data), pos, dstBuf);
  54. break;
  55. case GUID:
  56. encodeUAGuid(((UA_Guid*) data), pos, dstBuf);
  57. break;
  58. case BYTE_STRING:
  59. encodeUAByteString(((UA_ByteString*) data), pos, dstBuf);
  60. break;
  61. case XML_ELEMENT:
  62. encodeXmlElement((UA_XmlElement*) data, pos, dstBuf);
  63. break;
  64. case NODE_ID:
  65. encodeUANodeId((UA_NodeId*) data, pos, dstBuf);
  66. break;
  67. case EXPANDED_NODE_ID:
  68. encodeExpandedNodeId((UA_ExpandedNodeId*) data, pos, dstBuf);
  69. break;
  70. case STATUS_CODE:
  71. encodeUInt32(*((UInt32*) data), pos, dstBuf);
  72. break;
  73. case QUALIFIED_NAME:
  74. encodeQualifiedName(((UA_QualifiedName*) data), pos, dstBuf);
  75. break;
  76. case LOCALIZED_TEXT:
  77. encodeLocalizedText(((UA_LocalizedText*) data), pos, dstBuf);
  78. break;
  79. case EXTENSION_OBJECT:
  80. encodeExtensionObject((UA_ExtensionObject*) data, pos, dstBuf);
  81. break;
  82. case DATA_VALUE:
  83. encodeDataValue((UA_DataValue*) data, pos, dstBuf);
  84. break;
  85. case VARIANT:
  86. encodeVariant((UA_Variant*) data, pos, dstBuf);
  87. break;
  88. case DIAGNOSTIC_INFO:
  89. encodeDiagnosticInfo((UA_DiagnosticInfo*) data, pos, dstBuf);
  90. break;
  91. }
  92. return UA_NO_ERROR;
  93. }
  94. Int32 decoder_decodeBuiltInDatatype(char const * srcBuf, Int32 type, Int32 *pos,
  95. void *dstStructure) {
  96. Boolean tmp;
  97. switch (type) {
  98. case BOOLEAN:
  99. decodeBoolean(srcBuf, pos, (Boolean*) dstStructure);
  100. break;
  101. case SBYTE:
  102. decodeSByte(srcBuf, pos, (SByte*) dstStructure);
  103. break;
  104. case BYTE:
  105. decodeByte(srcBuf, pos, (Byte*) dstStructure);
  106. break;
  107. case INT16:
  108. decodeInt16(srcBuf, pos, (Int16*) dstStructure);
  109. break;
  110. case UINT16:
  111. decodeUInt16(srcBuf, pos, (UInt16*) dstStructure);
  112. break;
  113. case INT32:
  114. decodeInt32(srcBuf, pos, (Int32*) dstStructure);
  115. break;
  116. case UINT32:
  117. decodeUInt32(srcBuf, pos, (UInt32*) dstStructure);
  118. break;
  119. case INT64:
  120. decodeInt64(srcBuf, pos, (Int64*) dstStructure);
  121. break;
  122. case UINT64:
  123. decodeUInt64(srcBuf, pos, (UInt64*) dstStructure);
  124. break;
  125. case FLOAT:
  126. decodeFloat(srcBuf, pos, (Float*) dstStructure);
  127. break;
  128. case DOUBLE:
  129. decodeDouble(srcBuf, pos, (Double*) dstStructure);
  130. break;
  131. case STRING:
  132. decodeUAByteString(srcBuf, pos, (UA_String*) dstStructure);
  133. break;
  134. case DATE_TIME:
  135. decodeUADateTime(srcBuf, pos, (UA_DateTime*) dstStructure);
  136. break;
  137. case GUID:
  138. decodeUAGuid(srcBuf, pos, (UA_Guid*) dstStructure);
  139. break;
  140. case BYTE_STRING:
  141. decodeUAByteString(srcBuf, pos, (UA_ByteString*) dstStructure);
  142. break;
  143. case XML_ELEMENT:
  144. decodeXmlElement(srcBuf, pos, (UA_XmlElement*) dstStructure);
  145. break;
  146. case NODE_ID:
  147. decodeUANodeId(srcBuf, pos, (UA_NodeId*) dstStructure);
  148. break;
  149. case EXPANDED_NODE_ID:
  150. decodeExpandedNodeId(srcBuf, pos, (UA_ExpandedNodeId*) dstStructure);
  151. break;
  152. case STATUS_CODE:
  153. decodeUAStatusCode(srcBuf, pos, (UA_StatusCode*) dstStructure);
  154. break;
  155. case QUALIFIED_NAME:
  156. decodeQualifiedName(srcBuf, pos, (UA_QualifiedName*) dstStructure);
  157. break;
  158. case LOCALIZED_TEXT:
  159. decodeLocalizedText(srcBuf, pos, (UA_LocalizedText*) dstStructure);
  160. break;
  161. case EXTENSION_OBJECT:
  162. decodeExtensionObject(srcBuf, pos, (UA_ExtensionObject*) dstStructure);
  163. break;
  164. case DATA_VALUE:
  165. decodeDataValue(srcBuf, pos, (UA_DataValue*) dstStructure);
  166. break;
  167. case VARIANT:
  168. decodeVariant(srcBuf, pos, (UA_Variant*) dstStructure);
  169. break;
  170. case DIAGNOSTIC_INFO:
  171. decodeDiagnosticInfo(srcBuf, pos, (UA_DiagnosticInfo*) dstStructure);
  172. break;
  173. }
  174. return UA_NO_ERROR;
  175. }
  176. /*
  177. Int32 decoder_decodeVariantBody(char *srcBuf,Int32 type,Int32 *pos, UA_VariantUnion *dstVariantUnion)
  178. {
  179. Int32 i = 0;
  180. dstVariantUnion->Array->Value->
  181. switch (type)
  182. {
  183. case BOOLEAN_ARRAY:
  184. (*(Boolean_Array*)dstArrayStructure).arrayLength = arrayLength;
  185. (*(Boolean_Array*)dstArrayStructure).data = (Boolean*)opcua_malloc(arrayLength * sizeof(Boolean));
  186. for(i = 0; i < arrayLength; i++)
  187. {
  188. decoder_decodeBuiltInDatatype(srcBuf,BOOLEAN,pos,&(*(Boolean_Array*)dstArrayStructure).data[i]);
  189. }
  190. if(arrayDim > 0)
  191. {
  192. (*(Boolean_Array*)dstArrayStructure).dimensions.data
  193. (*(Boolean_Array*)dstArrayStructure).dimensions->data = (Int32*)opcua_malloc(arrayDim->arrayLength * sizeof(Int32));
  194. (*(Boolean_Array*)dstArrayStructure).dimensions- = arrayDim;
  195. }
  196. else
  197. {
  198. (*(Boolean_Array*)dstArrayStructure).dimensions = 1;
  199. (*(Boolean_Array*)dstArrayStructure).data = (*(Boolean_Array*)dstArrayStructure);
  200. }
  201. break;
  202. case SBYTE_ARRAY:
  203. (*(SByte_Array*)dstArrayStructure).arrayLength = arrayLength;
  204. (*(SByte_Array*)dstArrayStructure).data = (SByte*)opcua_malloc(arrayLength * sizeof(SByte));
  205. for(i = 0; i < arrayLength; i++)
  206. {
  207. decoder_decodeBuiltInDatatype(srcBuf,SBYTE,pos,&(*(SByte_Array*)dstArrayStructure).data[i]);
  208. }
  209. break;
  210. case BYTE_ARRAY:
  211. (*(Byte_Array*)dstArrayStructure).arrayLength = arrayLength;
  212. (*(Byte_Array*)dstArrayStructure).data = (Byte*)opcua_malloc(arrayLength * sizeof(Byte));
  213. for(i = 0; i < arrayLength; i++)
  214. {
  215. decoder_decodeBuiltInDatatype(srcBuf,BYTE,pos,&(*(Byte_Array*)dstArrayStructure).data[i]);
  216. }
  217. break;
  218. case INT16_ARRAY:
  219. (*(Int16_Array*)dstArrayStructure).arrayLength = arrayLength;
  220. (*(Int16_Array*)dstArrayStructure).data = (Int16*)opcua_malloc(arrayLength * sizeof(Int16));
  221. for(i = 0; i < arrayLength; i++)
  222. {
  223. decoder_decodeBuiltInDatatype(srcBuf,INT16,pos,&(*(Int16_Array*)dstArrayStructure).data[i]);
  224. }
  225. break;
  226. case UINT16_ARRAY:
  227. (*(UInt16_Array*)dstArrayStructure).arrayLength = arrayLength;
  228. (*(UInt16_Array*)dstArrayStructure).data = (UInt16*)opcua_malloc(arrayLength * sizeof(UInt16));
  229. for(i = 0; i < arrayLength; i++)
  230. {
  231. decoder_decodeBuiltInDatatype(srcBuf,UINT16,pos,(*(UInt16_Array*)dstArrayStructure).data[i]);
  232. }
  233. break;
  234. case INT32_ARRAY:
  235. (*(Int32_Array*)dstArrayStructure).arrayLength = arrayLength;
  236. (*(Int32_Array*)dstArrayStructure).data = (Int32*)opcua_malloc(arrayLength * sizeof(Int32));
  237. for(i = 0; i < arrayLength; i++)
  238. {
  239. decoder_decodeBuiltInDatatype(srcBuf,INT32,pos,(*(Int32_Array*)dstArrayStructure).data[i]);
  240. }
  241. break;
  242. case UINT32_ARRAY:
  243. (*(UInt32_Array*)dstArrayStructure).arrayLength = arrayLength;
  244. (*(UInt32_Array*)dstArrayStructure).data = (UInt32*)opcua_malloc(arrayLength * sizeof(UInt32));
  245. for(i = 0; i < arrayLength; i++)
  246. {
  247. decoder_decodeBuiltInDatatype(srcBuf,UINT32,pos,(*(UInt32_Array*)dstArrayStructure).data[i]);
  248. }
  249. break;
  250. case INT64_ARRAY:
  251. (*(Int64_Array*)dstArrayStructure).arrayLength = arrayLength;
  252. (*(Int64_Array*)dstArrayStructure).data = (Int64*)opcua_malloc(arrayLength * sizeof(Int64));
  253. for(i = 0; i < arrayLength; i++)
  254. {
  255. decoder_decodeBuiltInDatatype(srcBuf,INT64,pos,(*(Int64_Array*)dstArrayStructure).data[i]);
  256. }
  257. break;
  258. case UINT64_ARRAY:
  259. (*(UInt64_Array*)dstArrayStructure).arrayLength = arrayLength;
  260. (*(UInt64_Array*)dstArrayStructure).data = (UInt64*)opcua_malloc(arrayLength * sizeof(UInt64));
  261. for(i = 0; i < arrayLength; i++)
  262. {
  263. decoder_decodeBuiltInDatatype(srcBuf,UINT64,pos,(*(UInt64_Array*)dstArrayStructure).data[i]);
  264. }
  265. break;
  266. case FLOAT_ARRAY:
  267. (*(Float_Array*)dstArrayStructure).arrayLength = arrayLength;
  268. (*(Float_Array*)dstArrayStructure).data = (Float*)opcua_malloc(arrayLength * sizeof(Float));
  269. for(i = 0; i < arrayLength; i++)
  270. {
  271. decoder_decodeBuiltInDatatype(srcBuf,FLOAT,pos,(*(Float_Array*)dstArrayStructure).data[i]);
  272. }
  273. break;
  274. case DOUBLE_ARRAY:
  275. (*(Double_Array*)dstArrayStructure).arrayLength = arrayLength;
  276. (*(Double_Array*)dstArrayStructure).data = (Double*)opcua_malloc(arrayLength * sizeof(Double));
  277. for(i = 0; i < arrayLength; i++)
  278. {
  279. decoder_decodeBuiltInDatatype(srcBuf,DOUBLE,pos,(*(Double_Array*)dstArrayStructure).data[i]);
  280. }
  281. break;
  282. case STRING_ARRAY:
  283. (*(String_Array*)dstArrayStructure).arrayLength = arrayLength;
  284. (*(String_Array*)dstArrayStructure).data = (UA_String*)opcua_malloc(arrayLength * sizeof(UA_String));
  285. for(i = 0; i < arrayLength; i++)
  286. {
  287. decoder_decodeBuiltInDatatype(srcBuf,STRING,pos,(*(String_Array*)dstArrayStructure).data[i]);
  288. }
  289. break;
  290. case DATE_TIME_ARRAY:
  291. (*(DateTime_Array*)dstArrayStructure).arrayLength = arrayLength;
  292. (*(DateTime_Array*)dstArrayStructure).data = (UA_DateTime*)opcua_malloc(arrayLength * sizeof(UA_DateTime));
  293. for(i = 0; i < arrayLength; i++)
  294. {
  295. decoder_decodeBuiltInDatatype(srcBuf,DATE_TIME,pos,(*(DateTime_Array*)dstArrayStructure).data[i]);
  296. }
  297. break;
  298. case GUID_ARRAY:
  299. (*(Guid_Array*)dstArrayStructure).arrayLength = arrayLength;
  300. (*(Guid_Array*)dstArrayStructure).data = (UA_Guid*)opcua_malloc(arrayLength * sizeof(UA_Guid));
  301. for(i = 0; i < arrayLength; i++)
  302. {
  303. decoder_decodeBuiltInDatatype(srcBuf,GUID,pos,(*(Guid_Array*)dstArrayStructure).data[i]);
  304. }
  305. break;
  306. case BYTE_STRING_ARRAY:
  307. (*(ByteString_Array*)dstArrayStructure).arrayLength = arrayLength;
  308. (*(ByteString_Array*)dstArrayStructure).data = (UA_ByteString*)opcua_malloc(arrayLength * sizeof(UA_ByteString));
  309. for(i = 0; i < arrayLength; i++)
  310. {
  311. decoder_decodeBuiltInDatatype(srcBuf,BYTE_STRING,pos,(*(ByteString_Array*)dstArrayStructure).data[i]);
  312. }
  313. break;
  314. case XML_ELEMENT_ARRAY:
  315. (*(XmlElement_Array*)dstArrayStructure).arrayLength = arrayLength;
  316. (*(XmlElement_Array*)dstArrayStructure).data = (UA_XmlElement*)opcua_malloc(arrayLength * sizeof(UA_XmlElement));
  317. for(i = 0; i < arrayLength; i++)
  318. {
  319. decoder_decodeBuiltInDatatype(srcBuf,XML_ELEMENT,pos,(*(XmlElement_Array*)dstArrayStructure).data[i]);
  320. }
  321. break;
  322. case NODE_ID_ARRAY:
  323. (*(NodeId_Array*)dstArrayStructure).arrayLength = arrayLength;
  324. (*(NodeId_Array*)dstArrayStructure).data = (UA_NodeId*)opcua_malloc(arrayLength * sizeof(UA_NodeId));
  325. for(i = 0; i < arrayLength; i++)
  326. {
  327. decoder_decodeBuiltInDatatype(srcBuf,NODE_ID,pos,(*(NodeId_Array*)dstArrayStructure).data[i]);
  328. }
  329. break;
  330. case EXPANDED_NODE_ID_ARRAY:
  331. (*(ExpandedNodeId_Array*)dstArrayStructure).arrayLength = arrayLength;
  332. (*(NodeId_Array*)dstArrayStructure).data = (UA_ExpandedNodeId*)opcua_malloc(arrayLength * sizeof(UA_ExpandedNodeId));
  333. for(i = 0; i < arrayLength; i++)
  334. {
  335. decoder_decodeBuiltInDatatype(srcBuf,EXPANDED_NODE_ID,pos,(*(ExpandedNodeId_Array*)dstArrayStructure).data[i]);
  336. }
  337. break;
  338. case STATUS_CODE_ARRAY:
  339. (*(StatusCode_Array*)dstArrayStructure).arrayLength = arrayLength;
  340. (*(StatusCode_Array*)dstArrayStructure).data = (UA_StatusCode*)opcua_malloc(arrayLength * sizeof(UA_StatusCode));
  341. for(i = 0; i < arrayLength; i++)
  342. {
  343. decoder_decodeBuiltInDatatype(srcBuf,STATUS_CODE,pos,(*(StatusCode_Array*)dstArrayStructure).data[i]);
  344. }
  345. break;
  346. case QUALIFIED_NAME_ARRAY:
  347. (*(QualifiedName_Array*)dstArrayStructure).arrayLength = arrayLength;
  348. (*(QualifiedName_Array*)dstArrayStructure).data = (UA_QualifiedName*)opcua_malloc(arrayLength * sizeof(UA_QualifiedName));
  349. for(i = 0; i < arrayLength; i++)
  350. {
  351. decoder_decodeBuiltInDatatype(srcBuf,QUALIFIED_NAME,pos,(*(QualifiedName_Array*)dstArrayStructure).data[i]);
  352. }
  353. break;
  354. case LOCALIZED_TEXT_ARRAY:
  355. (*(LocalizedText_Array*)dstArrayStructure).arrayLength = arrayLength;
  356. (*(LocalizedText_Array*)dstArrayStructure).data = (UA_LocalizedText*)opcua_malloc(arrayLength * sizeof(UA_LocalizedText));
  357. for(i = 0; i < arrayLength; i++)
  358. {
  359. decoder_decodeBuiltInDatatype(srcBuf,LOCALIZED_TEXT,pos,(*(LocalizedText_Array*)dstArrayStructure).data[i]);
  360. }
  361. break;
  362. case EXTENSION_OBJECT_ARRAY:
  363. (*(ExtensionObject_Array*)dstArrayStructure).arrayLength = arrayLength;
  364. (*(LocalizedText_Array*)dstArrayStructure).data = (UA_ExtensionObject*)opcua_malloc(arrayLength * sizeof(UA_ExtensionObject));
  365. for(i = 0; i < arrayLength; i++)
  366. {
  367. decoder_decodeBuiltInDatatype(srcBuf,EXTENSION_OBJECT,pos,(*(ExtensionObject_Array*)dstArrayStructure).data[i]);
  368. }
  369. break;
  370. case DATA_VALUE_ARRAY:
  371. (*(DataValue_Array*)dstArrayStructure).arrayLength = arrayLength;
  372. (*(DataValue_Array*)dstArrayStructure).data = (UA_DataValue*)opcua_malloc(arrayLength * sizeof(UA_DataValue));
  373. for(i = 0; i < arrayLength; i++)
  374. {
  375. decoder_decodeBuiltInDatatype(srcBuf,DATA_VALUE,pos,(*(DataValue_Array*)dstArrayStructure).data[i]);
  376. }
  377. break;
  378. case VARIANT_ARRAY:
  379. (*(Variant_Array*)dstArrayStructure).arrayLength = arrayLength;
  380. (*(DataValue_Array*)dstArrayStructure).data = (UA_Variant*)opcua_malloc(arrayLength * sizeof(UA_Variant));
  381. for(i = 0; i < arrayLength; i++)
  382. {
  383. decoder_decodeBuiltInDatatype(srcBuf,VARIANT,pos,(*(Variant_Array)dstArrayStructure).data[i]);
  384. }
  385. break;
  386. case DIAGNOSTIC_INFO_ARRAY:
  387. (*(DiagnosticInfo_Array*)dstArrayStructure).arrayLength = arrayLength;
  388. (*(DiagnosticInfo_Array*)dstArrayStructure).data = (UA_DiagnosticInfo*)opcua_malloc(arrayLength * sizeof(UA_DiagnosticInfo));
  389. for(i = 0; i < arrayLength; i++)
  390. {
  391. decoder_decodeBuiltInDatatype(srcBuf,DIAGNOSTIC_INFO,pos,(*(DiagnosticInfo_Array)dstArrayStructure).data[i]);
  392. }
  393. break;
  394. }
  395. return UA_NO_ERROR;
  396. }
  397. /* not tested, needs to be reimplemented */
  398. Int32 encode_builtInDatatypeArray(void* data[], Int32 size, Int32 type,
  399. Int32 *pos, char *dstBuf) {
  400. int i;
  401. printf("encode_builtInDatatypeArray - size=%d, data=%p\n", size, data);
  402. // encode length of array
  403. encodeUInt32(size, pos, dstBuf);
  404. // now iterate over array
  405. for (i = 0; i < size; i++) {
  406. printf("encode_builtInDatatypeArray - pItem=%p", data[i]);
  407. if (type == BYTE_STRING) {
  408. UA_ByteString* p = (UA_ByteString*) data[i];
  409. printf(", item={l=%d,m=%.*s\n}", p->Length, p->Length, p->Data);
  410. } else {
  411. printf("\n");
  412. }
  413. encoder_encodeBuiltInDatatype(data[i], type, pos, dstBuf);
  414. }
  415. return UA_NO_ERROR;
  416. }
  417. Int32 decodeBoolean(char const * buf, Int32 *pos, Boolean *dst) {
  418. *dst = ((Boolean) (buf[*pos]) > 0) ? UA_TRUE : UA_FALSE;
  419. return UA_NO_ERROR;
  420. }
  421. void encodeBoolean(Boolean value, Int32 *pos, char *dstBuf) {
  422. Boolean tmpBool = ((value > 0) ? UA_TRUE : UA_FALSE);
  423. memcpy(&(dstBuf[*pos]), &tmpBool, sizeof(Boolean));
  424. }
  425. Int32 decodeSByte(char const * buf, Int32 *pos, SByte *dst) {
  426. *pos = (*pos) + 1;
  427. *dst = (SByte) buf[(*pos) - 1];
  428. return UA_NO_ERROR;
  429. }
  430. void encodeSByte(SByte value, Int32 *pos, char *dstBuf) {
  431. memcpy(&(dstBuf[*pos]), &value, sizeof(SByte));
  432. *pos = (*pos) + 1;
  433. }
  434. Int32 decodeByte(char const * buf, Int32 *pos, Byte* dst) {
  435. *pos = (*pos) + 1;
  436. *dst = (Byte) buf[(*pos) - 1];
  437. return UA_NO_ERROR;
  438. }
  439. void encodeByte(Byte value, Int32 *pos, char *dstBuf) {
  440. memcpy(&(dstBuf[*pos]), &value, sizeof(Byte));
  441. *pos = (*pos) + 1;
  442. }
  443. Int32 decodeUInt16(char const * buf, Int32 *pos, UInt16 *dst) {
  444. Byte t1 = buf[*pos];
  445. UInt16 t2 = (UInt16) (buf[*pos + 1] << 8);
  446. *pos += 2;
  447. *dst = t1 + t2;
  448. return UA_NO_ERROR;
  449. }
  450. void encodeUInt16(UInt16 value, Int32 *pos, char* dstBuf) {
  451. memcpy(&(dstBuf[*pos]), &value, sizeof(UInt16));
  452. *pos = (*pos) + sizeof(UInt16);
  453. }
  454. Int32 decodeInt16(char const * buf, Int32 *pos, Int16 *dst) {
  455. Int16 t1 = (Int16) (((SByte) (buf[*pos]) & 0xFF));
  456. Int16 t2 = (Int16) (((SByte) (buf[*pos + 1]) & 0xFF) << 8);
  457. *pos += 2;
  458. *dst = t1 + t2;
  459. return UA_NO_ERROR;
  460. }
  461. void encodeInt16(Int16 value, Int32 *pos, char *dstBuf) {
  462. memcpy(&(dstBuf[*pos]), &value, sizeof(Int16));
  463. *pos = (*pos) + sizeof(Int16);
  464. }
  465. Int32 decodeInt32(char const * buf, Int32 *pos, Int32 *dst) {
  466. Int32 t1 = (Int32) (((SByte) (buf[*pos]) & 0xFF));
  467. Int32 t2 = (Int32) (((SByte) (buf[*pos + 1]) & 0xFF) << 8);
  468. Int32 t3 = (Int32) (((SByte) (buf[*pos + 2]) & 0xFF) << 16);
  469. Int32 t4 = (Int32) (((SByte) (buf[*pos + 3]) & 0xFF) << 24);
  470. *pos += sizeof(Int32);
  471. *dst = t1 + t2 + t3 + t4;
  472. return UA_NO_ERROR;
  473. }
  474. void encodeInt32(Int32 value, Int32 *pos, char *dstBuf) {
  475. memcpy(&(dstBuf[*pos]), &value, sizeof(Int32));
  476. *pos = (*pos) + sizeof(Int32);
  477. }
  478. Int32 decodeUInt32(char const * buf, Int32 *pos, UInt32 *dst) {
  479. Byte t1 = buf[*pos];
  480. UInt32 t2 = (UInt32) buf[*pos + 1] << 8;
  481. UInt32 t3 = (UInt32) buf[*pos + 2] << 16;
  482. UInt32 t4 = (UInt32) buf[*pos + 3] << 24;
  483. *pos += sizeof(UInt32);
  484. *dst = t1 + t2 + t3 + t4;
  485. return UA_NO_ERROR;
  486. }
  487. void encodeUInt32(UInt32 value, Int32 *pos, char *dstBuf) {
  488. memcpy(&(dstBuf[*pos]), &value, sizeof(UInt32));
  489. *pos += 4;
  490. }
  491. Int32 decodeInt64(char const * buf, Int32 *pos, Int64 *dst) {
  492. SByte t1 = buf[*pos];
  493. Int64 t2 = (Int64) buf[*pos + 1] << 8;
  494. Int64 t3 = (Int64) buf[*pos + 2] << 16;
  495. Int64 t4 = (Int64) buf[*pos + 3] << 24;
  496. Int64 t5 = (Int64) buf[*pos + 4] << 32;
  497. Int64 t6 = (Int64) buf[*pos + 5] << 40;
  498. Int64 t7 = (Int64) buf[*pos + 6] << 48;
  499. Int64 t8 = (Int64) buf[*pos + 7] << 56;
  500. *pos += 8;
  501. *dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
  502. return UA_NO_ERROR;
  503. }
  504. void encodeInt64(Int64 value, Int32 *pos, char *dstBuf) {
  505. memcpy(&(dstBuf[*pos]), &value, sizeof(Int64));
  506. *pos = (*pos) + sizeof(Int64);
  507. }
  508. Int32 decodeUInt64(char const * buf, Int32 *pos, UInt64 *dst) {
  509. Byte t1 = buf[*pos];
  510. UInt64 t2 = (UInt64) buf[*pos + 1] << 8;
  511. UInt64 t3 = (UInt64) buf[*pos + 2] << 16;
  512. UInt64 t4 = (UInt64) buf[*pos + 3] << 24;
  513. UInt64 t5 = (UInt64) buf[*pos + 4] << 32;
  514. UInt64 t6 = (UInt64) buf[*pos + 5] << 40;
  515. UInt64 t7 = (UInt64) buf[*pos + 6] << 48;
  516. UInt64 t8 = (UInt64) buf[*pos + 7] << 56;
  517. *pos += 8;
  518. *dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
  519. return UA_NO_ERROR;
  520. }
  521. void encodeUInt64(UInt64 value, Int32 *pos, char *dstBuf) {
  522. memcpy(&(dstBuf[*pos]), &value, sizeof(UInt64));
  523. *pos = (*pos) + sizeof(UInt64);
  524. }
  525. Int32 decodeFloat(char const * buf, Int32 *pos, Float *dst) {
  526. Float tmpFloat;
  527. memcpy(&tmpFloat, &(buf[*pos]), sizeof(Float));
  528. *pos += sizeof(Float);
  529. *dst = tmpFloat;
  530. return UA_NO_ERROR;
  531. }
  532. Int32 encodeFloat(Float value, Int32 *pos, char *dstBuf) {
  533. memcpy(&(dstBuf[*pos]), &value, sizeof(Float));
  534. *pos += sizeof(Float);
  535. return UA_NO_ERROR;
  536. }
  537. Int32 decodeDouble(char const * buf, Int32 *pos, Double *dst) {
  538. Double tmpDouble;
  539. tmpDouble = (Double) (buf[*pos]);
  540. *pos += sizeof(Double);
  541. *dst = tmpDouble;
  542. return UA_NO_ERROR;
  543. }
  544. Int32 encodeDouble(Double value, Int32 *pos, char *dstBuf) {
  545. memcpy(&(dstBuf[*pos]), &value, sizeof(Double));
  546. *pos *= sizeof(Double);
  547. return UA_NO_ERROR;
  548. }
  549. Int32 decodeUAString(char const * buf, Int32 *pos, UA_String * dstUAString) {
  550. decoder_decodeBuiltInDatatype(buf, INT32, pos, &(dstUAString->Length));
  551. if (dstUAString->Length > 0) {
  552. dstUAString->Data = &(buf[*pos]);
  553. } else {
  554. dstUAString->Length = 0;
  555. dstUAString->Data = (void*) 0;
  556. }
  557. *pos += dstUAString->Length;
  558. return 0;
  559. }
  560. Int32 encodeUAString(UA_String *string, Int32 *pos, char *dstBuf) {
  561. if (string->Length > 0) {
  562. memcpy(&(dstBuf[*pos]), &(string->Length), sizeof(Int32));
  563. *pos += sizeof(Int32);
  564. memcpy(&(dstBuf[*pos]), string->Data, string->Length);
  565. *pos += string->Length;
  566. } else {
  567. int lengthNULL = 0xFFFFFFFF;
  568. memcpy(&(dstBuf[*pos]), &lengthNULL, sizeof(Int32));
  569. *pos += sizeof(Int32);
  570. }
  571. return 0;
  572. }
  573. Int32 UAString_calcSize(UA_String *string) {
  574. if (string->Length > 0) {
  575. return string->Length + sizeof(string->Length);
  576. } else {
  577. return sizeof(Int32);
  578. }
  579. }
  580. Int32 decodeUADateTime(char const * buf, Int32 *pos, UA_DateTime *dst) {
  581. decoder_decodeBuiltInDatatype(buf, INT64, pos, dst);
  582. return UA_NO_ERROR;
  583. }
  584. void encodeUADateTime(UA_DateTime time, Int32 *pos, char *dstBuf) {
  585. encodeInt64(time, pos, dstBuf);
  586. }
  587. Int32 decodeUAGuid(char const * buf, Int32 *pos, UA_Guid *dstGUID) {
  588. decoder_decodeBuiltInDatatype(buf, INT32, pos, &(dstGUID->Data1));
  589. decoder_decodeBuiltInDatatype(buf, INT16, pos, &(dstGUID->Data2));
  590. decoder_decodeBuiltInDatatype(buf, INT16, pos, &(dstGUID->Data3));
  591. decoder_decodeBuiltInDatatype(buf, STRING, pos, &(dstGUID->Data4));
  592. decodeUAByteString(buf, pos, &(dstGUID->Data4));
  593. return UA_NO_ERROR;
  594. }
  595. Int32 encodeUAGuid(UA_Guid *srcGuid, Int32 *pos, char *buf) {
  596. encodeUInt32(srcGuid->Data1, pos, buf);
  597. encodeUInt16(srcGuid->Data2, pos, buf);
  598. encodeUInt16(srcGuid->Data3, pos, buf);
  599. encodeUAByteString(srcGuid->Data4, pos, buf);
  600. return UA_NO_ERROR;
  601. }
  602. Int32 UAGuid_calcSize(UA_Guid *guid) {
  603. return sizeof(guid->Data1) + sizeof(guid->Data2) + sizeof(guid->Data3)
  604. + UAByteString_calcSize(&(guid->Data4));
  605. }
  606. Int32 decodeUAByteString(char const * buf, Int32* pos,
  607. UA_ByteString *dstBytestring) {
  608. return decodeUAString(buf, pos, (UA_String*) dstBytestring);
  609. }
  610. Int32 encodeUAByteString(UA_ByteString *srcByteString, Int32* pos, char *dstBuf) {
  611. return encodeUAString((UA_String*) srcByteString, pos, dstBuf);
  612. }
  613. Int32 encodeXmlElement(UA_XmlElement *xmlElement, Int32 *pos, char *dstBuf) {
  614. return encodeUAByteString(&(xmlElement->Data), pos, dstBuf);
  615. }
  616. Int32 decodeXmlElement(char const * buf, Int32* pos, UA_XmlElement *xmlElement) {
  617. return decodeUAByteString(buf, pos, &xmlElement->Data);
  618. }
  619. Int32 UAByteString_calcSize(UA_ByteString *byteString) {
  620. return UAString_calcSize((UA_String*) byteString);
  621. }
  622. /* Serialization of UANodeID is specified in 62541-6, §5.2.2.9 */
  623. Int32 decodeUANodeId(char const * buf, Int32 *pos, UA_NodeId *dstNodeId) {
  624. // Vars for overcoming decoder_decodeXXX's non-endian-savenes
  625. Byte dstByte;
  626. UInt16 dstUInt16;
  627. decoder_decodeBuiltInDatatype(buf, BYTE, pos, &(dstNodeId->EncodingByte));
  628. switch (dstNodeId->EncodingByte) {
  629. case NIEVT_TWO_BYTE: // Table 7
  630. decoder_decodeBuiltInDatatype(buf, BYTE, pos, &dstByte);
  631. dstNodeId->Identifier.Numeric = dstByte;
  632. dstNodeId->Namespace = 0; // default OPC UA Namespace
  633. break;
  634. case NIEVT_FOUR_BYTE: // Table 8
  635. decoder_decodeBuiltInDatatype(buf, BYTE, pos, &dstByte);
  636. dstNodeId->Namespace = dstByte;
  637. decoder_decodeBuiltInDatatype(buf, UINT16, pos, &dstUInt16);
  638. dstNodeId->Identifier.Numeric = dstUInt16;
  639. break;
  640. case NIEVT_NUMERIC: // Table 6, first entry
  641. decoder_decodeBuiltInDatatype(buf, UINT16, pos,
  642. &(dstNodeId->Namespace));
  643. decoder_decodeBuiltInDatatype(buf, UINT32, pos,
  644. &(dstNodeId->Identifier.Numeric));
  645. break;
  646. case NIEVT_STRING: // Table 6, second entry
  647. decoder_decodeBuiltInDatatype(buf, UINT16, pos,
  648. &(dstNodeId->Namespace));
  649. decoder_decodeBuiltInDatatype(buf, STRING, pos,
  650. &(dstNodeId->Identifier.String));
  651. break;
  652. case NIEVT_GUID: // Table 6, third entry
  653. decoder_decodeBuiltInDatatype(buf, UINT16, pos,
  654. &(dstNodeId->Namespace));
  655. decoder_decodeBuiltInDatatype(buf, GUID, pos,
  656. &(dstNodeId->Identifier.Guid));
  657. break;
  658. case NIEVT_BYTESTRING: // Table 6, "OPAQUE"
  659. decoder_decodeBuiltInDatatype(buf, UINT16, pos,
  660. &(dstNodeId->Namespace));
  661. decoder_decodeBuiltInDatatype(buf, BYTE_STRING, pos,
  662. &(dstNodeId->Identifier.ByteString));
  663. break;
  664. }
  665. return UA_NO_ERROR;
  666. }
  667. Int32 encodeUANodeId(UA_NodeId *srcNodeId, Int32 *pos, char *buf) {
  668. buf[*pos] = srcNodeId->EncodingByte;
  669. *pos += sizeof(Byte);
  670. switch (srcNodeId->EncodingByte) {
  671. case NIEVT_TWO_BYTE:
  672. memcpy(&(buf[*pos]), &(srcNodeId->Identifier.Numeric), sizeof(Byte));
  673. *pos += sizeof(Byte);
  674. break;
  675. case NIEVT_FOUR_BYTE:
  676. encodeByte((Byte) (srcNodeId->Namespace & 0xFF), pos, buf);
  677. encodeUInt16((UInt16) (srcNodeId->Identifier.Numeric & 0xFFFF), pos,
  678. buf);
  679. break;
  680. case NIEVT_NUMERIC:
  681. encodeUInt16((UInt16) (srcNodeId->Namespace & 0xFFFF), pos, buf);
  682. encodeUInt32(srcNodeId->Identifier.Numeric, pos, buf);
  683. break;
  684. case NIEVT_STRING:
  685. encodeUInt16(srcNodeId->Namespace, pos, buf);
  686. encodeUAString(&(srcNodeId->Identifier.String), pos, buf);
  687. break;
  688. case NIEVT_GUID:
  689. encodeUInt16(srcNodeId->Namespace, pos, buf);
  690. encodeUAGuid(&(srcNodeId->Identifier.Guid), pos, buf);
  691. break;
  692. case NIEVT_BYTESTRING:
  693. encodeUInt16(srcNodeId->Namespace, pos, buf);
  694. encodeUAByteString(&(srcNodeId->Identifier.ByteString), pos, buf);
  695. break;
  696. }
  697. return UA_NO_ERROR;
  698. }
  699. Int32 nodeId_calcSize(UA_NodeId *nodeId) {
  700. Int32 length = 0;
  701. switch (nodeId->EncodingByte) {
  702. case NIEVT_TWO_BYTE:
  703. length += 2 * sizeof(Byte);
  704. break;
  705. case NIEVT_FOUR_BYTE:
  706. length += 4 * sizeof(Byte);
  707. break;
  708. case NIEVT_NUMERIC:
  709. length += sizeof(Byte) + sizeof(UInt16) + sizeof(UInt32);
  710. break;
  711. case NIEVT_STRING:
  712. length += sizeof(Byte) + sizeof(UInt16) + sizeof(UInt32)
  713. + nodeId->Identifier.String.Length;
  714. break;
  715. case NIEVT_GUID:
  716. length += sizeof(Byte) + sizeof(UInt16) + sizeof(UInt32)
  717. + sizeof(UInt16) + sizeof(UInt16) + 8 * sizeof(Byte);
  718. break;
  719. case NIEVT_BYTESTRING:
  720. length += sizeof(Byte) + sizeof(UInt16) + sizeof(UInt32)
  721. + nodeId->Identifier.ByteString.Length;
  722. break;
  723. default:
  724. break;
  725. }
  726. return length;
  727. }
  728. /**
  729. * IntegerId
  730. * Part: 4
  731. * Chapter: 7.13
  732. * Page: 118
  733. */
  734. Int32 decodeIntegerId(char const * buf, Int32 *pos, Int32 *dst) {
  735. decoder_decodeBuiltInDatatype(buf, INT32, pos, dst);
  736. return UA_NO_ERROR;
  737. }
  738. void encodeIntegerId(UA_AD_IntegerId integerId, Int32 *pos, char *buf) {
  739. encodeInt32(integerId, pos, buf);
  740. }
  741. Int32 decodeExpandedNodeId(char const * buf, Int32 *pos,
  742. UA_ExpandedNodeId *nodeId) {
  743. decoder_decodeBuiltInDatatype(buf, BYTE, pos,
  744. &(nodeId->NodeId.EncodingByte));
  745. switch (nodeId->NodeId.EncodingByte) {
  746. case NIEVT_TWO_BYTE:
  747. decoder_decodeBuiltInDatatype(buf, BYTE, pos,
  748. &(nodeId->NodeId.Identifier.Numeric));
  749. break;
  750. case NIEVT_FOUR_BYTE:
  751. decoder_decodeBuiltInDatatype(buf, UINT16, pos,
  752. &(nodeId->NodeId.Identifier.Numeric));
  753. break;
  754. case NIEVT_NUMERIC:
  755. decoder_decodeBuiltInDatatype(buf, UINT32, pos,
  756. &(nodeId->NodeId.Identifier.Numeric));
  757. break;
  758. case NIEVT_STRING:
  759. decoder_decodeBuiltInDatatype(buf, STRING, pos,
  760. &(nodeId->NodeId.Identifier.String));
  761. break;
  762. case NIEVT_GUID:
  763. decoder_decodeBuiltInDatatype(buf, GUID, pos,
  764. &(nodeId->NodeId.Identifier.Guid));
  765. break;
  766. case NIEVT_BYTESTRING:
  767. decoder_decodeBuiltInDatatype(buf, BYTE_STRING, pos,
  768. &(nodeId->NodeId.Identifier.ByteString));
  769. break;
  770. }
  771. if (nodeId->NodeId.EncodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  772. nodeId->NodeId.Namespace = 0;
  773. decoder_decodeBuiltInDatatype(buf, STRING, pos,
  774. &(nodeId->NamespaceUri));
  775. }
  776. if (nodeId->NodeId.EncodingByte & NIEVT_SERVERINDEX_FLAG) {
  777. decoder_decodeBuiltInDatatype(buf, UINT32, pos, &(nodeId->ServerIndex));
  778. }
  779. return UA_NO_ERROR;
  780. }
  781. Int32 encodeExpandedNodeId(UA_ExpandedNodeId *nodeId, Int32 *pos, char *dstBuf) {
  782. encoder_encodeBuiltInDatatype((void*) &(nodeId->NodeId.EncodingByte), BYTE,
  783. pos, dstBuf);
  784. switch (nodeId->NodeId.EncodingByte) {
  785. case NIEVT_TWO_BYTE:
  786. encoder_encodeBuiltInDatatype(
  787. (void*) &(nodeId->NodeId.Identifier.Numeric), BYTE, pos,
  788. dstBuf);
  789. break;
  790. case NIEVT_FOUR_BYTE:
  791. encoder_encodeBuiltInDatatype(
  792. (void*) &(nodeId->NodeId.Identifier.Numeric), UINT16, pos,
  793. dstBuf);
  794. break;
  795. case NIEVT_NUMERIC:
  796. encoder_encodeBuiltInDatatype(
  797. (void*) &(nodeId->NodeId.Identifier.Numeric), UINT32, pos,
  798. dstBuf);
  799. break;
  800. case NIEVT_STRING:
  801. encoder_encodeBuiltInDatatype(
  802. (void*) &(nodeId->NodeId.Identifier.String), STRING, pos,
  803. dstBuf);
  804. break;
  805. case NIEVT_GUID:
  806. encoder_encodeBuiltInDatatype((void*) &(nodeId->NodeId.Identifier.Guid),
  807. STRING, pos, dstBuf);
  808. break;
  809. case NIEVT_BYTESTRING:
  810. encoder_encodeBuiltInDatatype(
  811. (void*) &(nodeId->NodeId.Identifier.ByteString), BYTE_STRING,
  812. pos, dstBuf);
  813. break;
  814. }
  815. if (nodeId->NodeId.EncodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  816. nodeId->NodeId.Namespace = 0;
  817. encoder_encodeBuiltInDatatype((void*) &(nodeId->NamespaceUri), STRING,
  818. pos, dstBuf);
  819. }
  820. if (nodeId->NodeId.EncodingByte & NIEVT_SERVERINDEX_FLAG) {
  821. encoder_encodeBuiltInDatatype((void*) &(nodeId->ServerIndex), UINT32,
  822. pos, dstBuf);
  823. }
  824. return UA_NO_ERROR;
  825. }
  826. Int32 ExpandedNodeId_calcSize(UA_ExpandedNodeId *nodeId) {
  827. Int32 length = 0;
  828. length += sizeof(UInt32); //nodeId->NodeId.EncodingByte
  829. switch (nodeId->NodeId.EncodingByte) {
  830. case NIEVT_TWO_BYTE:
  831. length += sizeof(Byte); //nodeId->NodeId.Identifier.Numeric
  832. break;
  833. case NIEVT_FOUR_BYTE:
  834. length += sizeof(UInt16); //nodeId->NodeId.Identifier.Numeric
  835. break;
  836. case NIEVT_NUMERIC:
  837. length += sizeof(UInt32); //nodeId->NodeId.Identifier.Numeric
  838. break;
  839. case NIEVT_STRING:
  840. //nodeId->NodeId.Identifier.String
  841. length += UAString_calcSize(&(nodeId->NodeId.Identifier.String));
  842. break;
  843. case NIEVT_GUID:
  844. //nodeId->NodeId.Identifier.Guid
  845. length += UAGuid_calcSize(&(nodeId->NodeId.Identifier.Guid));
  846. break;
  847. case NIEVT_BYTESTRING:
  848. //nodeId->NodeId.Identifier.ByteString
  849. length += UAByteString_calcSize(
  850. &(nodeId->NodeId.Identifier.ByteString));
  851. break;
  852. }
  853. if (nodeId->NodeId.EncodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  854. length += sizeof(UInt16); //nodeId->NodeId.Namespace
  855. length += UAString_calcSize(&(nodeId->NamespaceUri)); //nodeId->NamespaceUri
  856. }
  857. if (nodeId->NodeId.EncodingByte & NIEVT_SERVERINDEX_FLAG) {
  858. length += sizeof(UInt32); //nodeId->ServerIndex
  859. }
  860. return length;
  861. }
  862. Int32 decodeUAStatusCode(char const * buf, Int32 *pos, UA_StatusCode* dst) {
  863. decoder_decodeBuiltInDatatype(buf, UINT32, pos, dst);
  864. return UA_NO_ERROR;
  865. }
  866. Int32 decodeQualifiedName(char const * buf, Int32 *pos,
  867. UA_QualifiedName *dstQualifiedName) {
  868. //TODO memory management for ua string
  869. decoder_decodeBuiltInDatatype(buf, STRING, pos,
  870. &(dstQualifiedName->NamespaceIndex));
  871. decoder_decodeBuiltInDatatype(buf, STRING, pos, &(dstQualifiedName->Name));
  872. return UA_NO_ERROR;
  873. }
  874. Int32 encodeQualifiedName(UA_QualifiedName *qualifiedName, Int32 *pos,
  875. char *dstBuf) {
  876. encoder_encodeBuiltInDatatype((void*) &(qualifiedName->NamespaceIndex),
  877. UINT16, pos, dstBuf);
  878. encoder_encodeBuiltInDatatype((void*) &(qualifiedName->Name), STRING, pos,
  879. dstBuf);
  880. return UA_NO_ERROR;
  881. }
  882. Int32 QualifiedName_calcSize(UA_QualifiedName *qualifiedName) {
  883. Int32 length = 0;
  884. length += sizeof(UInt16); //qualifiedName->NamespaceIndex
  885. length += UAString_calcSize(&(qualifiedName->Name)); //qualifiedName->Name
  886. length += sizeof(UInt16); //qualifiedName->Reserved
  887. return length;
  888. }
  889. Int32 decodeLocalizedText(char const * buf, Int32 *pos,
  890. UA_LocalizedText *dstLocalizedText) {
  891. //TODO memory management for ua string
  892. decoder_decodeBuiltInDatatype(buf, BYTE, pos,
  893. &(dstLocalizedText->EncodingMask));
  894. decoder_decodeBuiltInDatatype(buf, STRING, pos,
  895. &(dstLocalizedText->Locale));
  896. decoder_decodeBuiltInDatatype(buf, STRING, pos, &(dstLocalizedText->Text));
  897. return UA_NO_ERROR;
  898. }
  899. Int32 encodeLocalizedText(UA_LocalizedText *localizedText, Int32 *pos,
  900. char *dstBuf) {
  901. if (localizedText->EncodingMask & 0x01) {
  902. encoder_encodeBuiltInDatatype((void*) &(localizedText->Locale), STRING,
  903. pos, dstBuf);
  904. }
  905. if (localizedText->EncodingMask & 0x02) {
  906. encoder_encodeBuiltInDatatype((void*) &(localizedText->Text), STRING,
  907. pos, dstBuf);
  908. }
  909. return UA_NO_ERROR;
  910. }
  911. Int32 LocalizedText_calcSize(UA_LocalizedText *localizedText) {
  912. Int32 length = 0;
  913. length += localizedText->EncodingMask;
  914. if (localizedText->EncodingMask & 0x01) {
  915. length += UAString_calcSize(&(localizedText->Locale));
  916. }
  917. if (localizedText->EncodingMask & 0x02) {
  918. length += UAString_calcSize(&(localizedText->Text));
  919. }
  920. return length;
  921. }
  922. Int32 decodeExtensionObject(char const * buf, Int32 *pos,
  923. UA_ExtensionObject *dstExtensionObject) {
  924. decoder_decodeBuiltInDatatype(buf, NODE_ID, pos,
  925. &(dstExtensionObject->TypeId));
  926. decoder_decodeBuiltInDatatype(buf, BYTE, pos,
  927. &(dstExtensionObject->Encoding));
  928. switch (dstExtensionObject->Encoding) {
  929. case NO_BODY_IS_ENCODED:
  930. break;
  931. case BODY_IS_BYTE_STRING:
  932. case BODY_IS_XML_ELEMENT:
  933. decoder_decodeBuiltInDatatype(buf, BYTE_STRING, pos,
  934. &(dstExtensionObject->Body));
  935. break;
  936. }
  937. return UA_NO_ERROR;
  938. }
  939. Int32 encodeExtensionObject(UA_ExtensionObject *extensionObject, Int32 *pos,
  940. char *dstBuf) {
  941. encoder_encodeBuiltInDatatype((void*) &(extensionObject->TypeId), NODE_ID,
  942. pos, dstBuf);
  943. encoder_encodeBuiltInDatatype((void*) &(extensionObject->Encoding), BYTE,
  944. pos, dstBuf);
  945. switch (extensionObject->Encoding) {
  946. case NO_BODY_IS_ENCODED:
  947. break;
  948. case BODY_IS_BYTE_STRING:
  949. case BODY_IS_XML_ELEMENT:
  950. encoder_encodeBuiltInDatatype((void*) &(extensionObject->Body),
  951. BYTE_STRING, pos, dstBuf);
  952. break;
  953. }
  954. return UA_NO_ERROR;
  955. }
  956. Int32 ExtensionObject_calcSize(UA_ExtensionObject *extensionObject) {
  957. Int32 length = 0;
  958. length += nodeId_calcSize(&(extensionObject->TypeId));
  959. length += sizeof(Byte); //extensionObject->Encoding
  960. switch (extensionObject->Encoding) {
  961. case 0x00:
  962. length += sizeof(Int32); //extensionObject->Body.Length
  963. break;
  964. case 0x01:
  965. length += UAByteString_calcSize(&(extensionObject->Body));
  966. break;
  967. case 0x02:
  968. length += UAByteString_calcSize(&(extensionObject->Body));
  969. break;
  970. }
  971. return length;
  972. }
  973. Int32 decodeVariant(char const * buf, Int32 *pos, UA_Variant *dstVariant) {
  974. decoder_decodeBuiltInDatatype(buf, BYTE, pos, &(dstVariant->EncodingMask));
  975. if (dstVariant->EncodingMask & (1 << 7)) {
  976. decoder_decodeBuiltInDatatype(buf, INT32, pos,
  977. &(dstVariant->ArrayLength));
  978. // dstVariant->Value->
  979. }
  980. //TODO implement the multiarray decoding
  981. return UA_NO_ERROR;
  982. }
  983. Int32 encodeVariant(UA_Variant *variant, Int32 *pos, char *dstBuf) {
  984. encoder_encodeBuiltInDatatype((void*) &(variant->EncodingMask), BYTE, pos,
  985. dstBuf);
  986. /* array of values is encoded */
  987. if (variant->EncodingMask & (1 << 7)) // array length is encoded
  988. {
  989. encoder_encodeBuiltInDatatype((void*) &(variant->ArrayLength), INT32,
  990. pos, dstBuf);
  991. if (variant->ArrayLength > 0) {
  992. //encode array as given by variant type
  993. encode_builtInDatatypeArray((void*) variant->Value,
  994. variant->ArrayLength, (variant->EncodingMask & 31), pos,
  995. dstBuf);
  996. }
  997. //single value to encode
  998. encoder_encodeBuiltInDatatype((void*) variant->Value,
  999. (variant->EncodingMask & 31), pos, dstBuf);
  1000. } else //single value to encode
  1001. {
  1002. encoder_encodeBuiltInDatatype((void*) variant->Value,
  1003. (variant->EncodingMask & 31), pos, dstBuf);
  1004. }
  1005. if (variant->EncodingMask & (1 << 6)) // encode array dimension field
  1006. {
  1007. encoder_encodeBuiltInDatatype((void*) variant->Value,
  1008. (variant->EncodingMask & 31), pos, dstBuf);
  1009. }
  1010. return UA_NO_ERROR;
  1011. }
  1012. Int32 Variant_calcSize(UA_Variant *variant) {
  1013. Int32 length = 0;
  1014. length += sizeof(Byte); //variant->EncodingMask
  1015. if (variant->EncodingMask & (1 << 7)) // array length is encoded
  1016. {
  1017. length += sizeof(Int32); //variant->ArrayLength
  1018. if (variant->ArrayLength > 0) {
  1019. //encode array as given by variant type
  1020. //ToDo: tobeInsert: length += the calcSize for VariantUnions
  1021. }
  1022. //single value to encode
  1023. //ToDo: tobeInsert: length += the calcSize for VariantUnions
  1024. } else //single value to encode
  1025. {
  1026. //ToDo: tobeInsert: length += the calcSize for VariantUnions
  1027. }
  1028. if (variant->EncodingMask & (1 << 6)) // encode array dimension field
  1029. {
  1030. //ToDo: tobeInsert: length += the calcSize for VariantUnions
  1031. }
  1032. return length;
  1033. }
  1034. Int32 decodeDataValue(char const * buf, Int32 *pos, UA_DataValue *dstDataValue) {
  1035. decoder_decodeBuiltInDatatype(buf, BYTE, pos,
  1036. &(dstDataValue->EncodingMask));
  1037. decoder_decodeBuiltInDatatype(buf, VARIANT, pos, &(dstDataValue->Value));
  1038. decoder_decodeBuiltInDatatype(buf, STATUS_CODE, pos,
  1039. &(dstDataValue->Status));
  1040. decoder_decodeBuiltInDatatype(buf, DATE_TIME, pos,
  1041. &(dstDataValue->SourceTimestamp));
  1042. decoder_decodeBuiltInDatatype(buf, UINT16, pos,
  1043. &(dstDataValue->SourcePicoseconds));
  1044. if (dstDataValue->SourcePicoseconds > MAX_PICO_SECONDS) {
  1045. dstDataValue->SourcePicoseconds = MAX_PICO_SECONDS;
  1046. }
  1047. decoder_decodeBuiltInDatatype(buf, DATE_TIME, pos,
  1048. &(dstDataValue->ServerTimestamp));
  1049. decoder_decodeBuiltInDatatype(buf, UINT16, pos,
  1050. &(dstDataValue->ServerPicoseconds));
  1051. if (dstDataValue->ServerPicoseconds > MAX_PICO_SECONDS) {
  1052. dstDataValue->ServerPicoseconds = MAX_PICO_SECONDS;
  1053. }
  1054. //TODO to be implemented
  1055. return UA_NO_ERROR;
  1056. }
  1057. Int32 encodeDataValue(UA_DataValue *dataValue, Int32 *pos, char *dstBuf) {
  1058. encoder_encodeBuiltInDatatype((void*) &(dataValue->EncodingMask), BYTE, pos,
  1059. dstBuf);
  1060. if (dataValue->EncodingMask & 0x01) {
  1061. encoder_encodeBuiltInDatatype((void*) &(dataValue->Value), VARIANT, pos,
  1062. dstBuf);
  1063. }
  1064. if (dataValue->EncodingMask & 0x02) {
  1065. encoder_encodeBuiltInDatatype((void*) &(dataValue->Status), STATUS_CODE,
  1066. pos, dstBuf);
  1067. }
  1068. if (dataValue->EncodingMask & 0x04) {
  1069. encoder_encodeBuiltInDatatype((void*) &(dataValue->SourceTimestamp),
  1070. DATE_TIME, pos, dstBuf);
  1071. }
  1072. if (dataValue->EncodingMask & 0x08) {
  1073. encoder_encodeBuiltInDatatype((void*) &(dataValue->ServerTimestamp),
  1074. DATE_TIME, pos, dstBuf);
  1075. }
  1076. if (dataValue->EncodingMask & 0x10) {
  1077. encoder_encodeBuiltInDatatype((void*) &(dataValue->SourcePicoseconds),
  1078. UINT16, pos, dstBuf);
  1079. }
  1080. if (dataValue->EncodingMask & 0x20) {
  1081. encoder_encodeBuiltInDatatype((void*) &(dataValue->ServerPicoseconds),
  1082. UINT16, pos, dstBuf);
  1083. }
  1084. return UA_NO_ERROR;
  1085. }
  1086. Int32 DataValue_calcSize(UA_DataValue *dataValue) {
  1087. Int32 length = 0;
  1088. length += sizeof(Byte); //dataValue->EncodingMask
  1089. if (dataValue->EncodingMask & 0x01) {
  1090. length += Variant_calcSize(&(dataValue->Value));
  1091. }
  1092. if (dataValue->EncodingMask & 0x02) {
  1093. length += sizeof(UInt32); //dataValue->Status
  1094. }
  1095. if (dataValue->EncodingMask & 0x04) {
  1096. length += sizeof(Int64); //dataValue->SourceTimestamp
  1097. }
  1098. if (dataValue->EncodingMask & 0x08) {
  1099. length += sizeof(Int64); //dataValue->ServerTimestamp
  1100. }
  1101. if (dataValue->EncodingMask & 0x10) {
  1102. length += sizeof(Int64); //dataValue->SourcePicoseconds
  1103. }
  1104. if (dataValue->EncodingMask & 0x20) {
  1105. length += sizeof(Int64); //dataValue->ServerPicoseconds
  1106. }
  1107. return length;
  1108. }
  1109. /**
  1110. * DiagnosticInfo
  1111. * Part: 4
  1112. * Chapter: 7.9
  1113. * Page: 116
  1114. */
  1115. Int32 decodeDiagnosticInfo(char const * buf, Int32 *pos,
  1116. UA_DiagnosticInfo *dstDiagnosticInfo) {
  1117. Byte encodingByte = (buf[*pos]);
  1118. Byte mask;
  1119. for (mask = 1; mask <= 0x40; mask << 2) {
  1120. switch (mask & encodingByte) {
  1121. case DIEMT_SYMBOLIC_ID:
  1122. decoder_decodeBuiltInDatatype(buf, INT32, pos,
  1123. &(dstDiagnosticInfo->SymbolicId));
  1124. //dstDiagnosticInfo->symbolicId = decodeInt32(buf, pos);
  1125. break;
  1126. case DIEMT_NAMESPACE:
  1127. decoder_decodeBuiltInDatatype(buf, INT32, pos,
  1128. &(dstDiagnosticInfo->NamespaceUri));
  1129. //dstDiagnosticInfo->namespaceUri = decodeInt32(buf, pos);
  1130. break;
  1131. case DIEMT_LOCALIZED_TEXT:
  1132. decoder_decodeBuiltInDatatype(buf, INT32, pos,
  1133. &(dstDiagnosticInfo->LocalizedText));
  1134. //dstDiagnosticInfo->localizesText = decodeInt32(buf, pos);
  1135. break;
  1136. case DIEMT_LOCALE:
  1137. decoder_decodeBuiltInDatatype(buf, INT32, pos,
  1138. &(dstDiagnosticInfo->Locale));
  1139. //dstDiagnosticInfo->locale = decodeInt32(buf, pos);
  1140. break;
  1141. case DIEMT_ADDITIONAL_INFO:
  1142. decoder_decodeBuiltInDatatype(buf, STRING, pos,
  1143. &(dstDiagnosticInfo->AdditionalInfo));
  1144. decodeUAString(buf, pos, &dstDiagnosticInfo->AdditionalInfo);
  1145. break;
  1146. case DIEMT_INNER_STATUS_CODE:
  1147. decoder_decodeBuiltInDatatype(buf, STATUS_CODE, pos,
  1148. &(dstDiagnosticInfo->InnerStatusCode));
  1149. //dstDiagnosticInfo->innerStatusCode = decodeUAStatusCode(buf, pos);
  1150. break;
  1151. case DIEMT_INNER_DIAGNOSTIC_INFO:
  1152. //TODO memory management should be checked (getting memory within a function)
  1153. dstDiagnosticInfo->InnerDiagnosticInfo =
  1154. (UA_DiagnosticInfo*) opcua_malloc(
  1155. sizeof(UA_DiagnosticInfo));
  1156. decoder_decodeBuiltInDatatype(buf, DIAGNOSTIC_INFO, pos,
  1157. &(dstDiagnosticInfo->InnerDiagnosticInfo));
  1158. break;
  1159. }
  1160. }
  1161. *pos += 1;
  1162. return 0;
  1163. }
  1164. Int32 encodeDiagnosticInfo(UA_DiagnosticInfo *diagnosticInfo, Int32 *pos,
  1165. char *dstbuf) {
  1166. Byte mask;
  1167. int i;
  1168. encoder_encodeBuiltInDatatype((void*) (&(diagnosticInfo->EncodingMask)),
  1169. BYTE, pos, dstbuf);
  1170. for (i = 0; i < 7; i++) {
  1171. switch ( (0x01 << i) & diagnosticInfo->EncodingMask) {
  1172. case DIEMT_SYMBOLIC_ID:
  1173. // puts("diagnosticInfo symbolic id");
  1174. encoder_encodeBuiltInDatatype((void*) &(diagnosticInfo->SymbolicId),
  1175. INT32, pos, dstbuf);
  1176. break;
  1177. case DIEMT_NAMESPACE:
  1178. encoder_encodeBuiltInDatatype(
  1179. (void*) &(diagnosticInfo->NamespaceUri), INT32, pos,
  1180. dstbuf);
  1181. break;
  1182. case DIEMT_LOCALIZED_TEXT:
  1183. encoder_encodeBuiltInDatatype(
  1184. (void*) &(diagnosticInfo->LocalizedText), INT32, pos,
  1185. dstbuf);
  1186. break;
  1187. case DIEMT_LOCALE:
  1188. encoder_encodeBuiltInDatatype((void*) &(diagnosticInfo->Locale),
  1189. INT32, pos, dstbuf);
  1190. break;
  1191. case DIEMT_ADDITIONAL_INFO:
  1192. encoder_encodeBuiltInDatatype(
  1193. (void*) &(diagnosticInfo->AdditionalInfo), STRING, pos,
  1194. dstbuf);
  1195. break;
  1196. case DIEMT_INNER_STATUS_CODE:
  1197. encoder_encodeBuiltInDatatype(
  1198. (void*) &(diagnosticInfo->InnerStatusCode), STATUS_CODE,
  1199. pos, dstbuf);
  1200. break;
  1201. case DIEMT_INNER_DIAGNOSTIC_INFO:
  1202. encoder_encodeBuiltInDatatype(
  1203. (void*) &(diagnosticInfo->InnerDiagnosticInfo),
  1204. DIAGNOSTIC_INFO, pos, dstbuf);
  1205. break;
  1206. }
  1207. }
  1208. return UA_NO_ERROR;
  1209. }
  1210. Int32 diagnosticInfo_calcSize(UA_DiagnosticInfo *diagnosticInfo) {
  1211. Int32 length = 0;
  1212. Byte mask;
  1213. length += sizeof(Byte); // EncodingMask
  1214. for (mask = 0x01; mask <= 0x40; mask *= 2) {
  1215. switch (mask & (diagnosticInfo->EncodingMask)) {
  1216. case DIEMT_SYMBOLIC_ID:
  1217. // puts("diagnosticInfo symbolic id");
  1218. length += sizeof(Int32);
  1219. break;
  1220. case DIEMT_NAMESPACE:
  1221. length += sizeof(Int32);
  1222. break;
  1223. case DIEMT_LOCALIZED_TEXT:
  1224. length += sizeof(Int32);
  1225. break;
  1226. case DIEMT_LOCALE:
  1227. length += sizeof(Int32);
  1228. break;
  1229. case DIEMT_ADDITIONAL_INFO:
  1230. length += UAString_calcSize(&(diagnosticInfo->AdditionalInfo));
  1231. break;
  1232. case DIEMT_INNER_STATUS_CODE:
  1233. length += sizeof(UA_StatusCode);
  1234. break;
  1235. case DIEMT_INNER_DIAGNOSTIC_INFO:
  1236. length += diagnosticInfo_calcSize(
  1237. diagnosticInfo->InnerDiagnosticInfo);
  1238. break;
  1239. }
  1240. }
  1241. return length;
  1242. }
  1243. /**
  1244. * RequestHeader
  1245. * Part: 4
  1246. * Chapter: 7.26
  1247. * Page: 132
  1248. */
  1249. /** \copydoc decodeRequestHeader */
  1250. Int32 decodeRequestHeader(const AD_RawMessage *srcRaw, Int32 *pos,
  1251. UA_AD_RequestHeader *dstRequestHeader) {
  1252. return decoder_decodeRequestHeader(srcRaw->message, pos, dstRequestHeader);
  1253. }
  1254. Int32 decoder_decodeRequestHeader(char const * message, Int32 *pos,
  1255. UA_AD_RequestHeader *dstRequestHeader) {
  1256. // 62541-4 §5.5.2.2 OpenSecureChannelServiceParameters
  1257. // requestHeader - common request parameters. The authenticationToken is always omitted
  1258. decoder_decodeBuiltInDatatype(message, NODE_ID, pos,
  1259. &(dstRequestHeader->authenticationToken));
  1260. decoder_decodeBuiltInDatatype(message, DATE_TIME, pos,
  1261. &(dstRequestHeader->timestamp));
  1262. decoder_decodeBuiltInDatatype(message, UINT32, pos,
  1263. &(dstRequestHeader->requestHandle));
  1264. decoder_decodeBuiltInDatatype(message, UINT32, pos,
  1265. &(dstRequestHeader->returnDiagnostics));
  1266. decoder_decodeBuiltInDatatype(message, STRING, pos,
  1267. &(dstRequestHeader->auditEntryId));
  1268. decoder_decodeBuiltInDatatype(message, UINT32, pos,
  1269. &(dstRequestHeader->timeoutHint));
  1270. decoder_decodeBuiltInDatatype(message, EXTENSION_OBJECT, pos,
  1271. &(dstRequestHeader->additionalHeader));
  1272. // AdditionalHeader will stay empty, need to be changed if there is relevant information
  1273. return 0;
  1274. }
  1275. /**
  1276. * ResponseHeader
  1277. * Part: 4
  1278. * Chapter: 7.27
  1279. * Page: 133
  1280. */
  1281. /** \copydoc encodeResponseHeader */
  1282. Int32 encodeResponseHeader(UA_AD_ResponseHeader const * responseHeader,
  1283. Int32 *pos, UA_ByteString *dstBuf) {
  1284. encodeUADateTime(responseHeader->timestamp, pos, dstBuf->Data);
  1285. encodeIntegerId(responseHeader->requestHandle, pos, dstBuf->Data);
  1286. encodeUInt32(responseHeader->serviceResult, pos, dstBuf->Data);
  1287. encodeDiagnosticInfo(responseHeader->serviceDiagnostics, pos, dstBuf->Data);
  1288. encode_builtInDatatypeArray(responseHeader->stringTable, responseHeader->noOfStringTable, BYTE_STRING, pos, dstBuf->Data);
  1289. encodeExtensionObject(responseHeader->additionalHeader,pos, dstBuf->Data);
  1290. return 0;
  1291. }
  1292. Int32 extensionObject_calcSize(UA_ExtensionObject *extensionObject) {
  1293. Int32 length = 0;
  1294. length += nodeId_calcSize(&(extensionObject->TypeId));
  1295. length += sizeof(Byte); //The EncodingMask Byte
  1296. if (extensionObject->Encoding == BODY_IS_BYTE_STRING
  1297. || extensionObject->Encoding == BODY_IS_XML_ELEMENT) {
  1298. length += UAByteString_calcSize(&(extensionObject->Body));
  1299. }
  1300. return length;
  1301. }
  1302. Int32 responseHeader_calcSize(UA_AD_ResponseHeader *responseHeader) {
  1303. Int32 i;
  1304. Int32 length = 0;
  1305. // UtcTime timestamp 8
  1306. length += sizeof(UA_DateTime);
  1307. // IntegerId requestHandle 4
  1308. length += sizeof(UA_AD_IntegerId);
  1309. // StatusCode serviceResult 4
  1310. length += sizeof(UA_StatusCode);
  1311. // DiagnosticInfo serviceDiagnostics
  1312. length += diagnosticInfo_calcSize(responseHeader->serviceDiagnostics);
  1313. // String stringTable[], see 62541-6 § 5.2.4
  1314. length += sizeof(Int32); // Length of Stringtable always
  1315. if (responseHeader->noOfStringTable > 0) {
  1316. for (i = 0; i < responseHeader->noOfStringTable; i++) {
  1317. length += UAString_calcSize(responseHeader->stringTable[i]);
  1318. }
  1319. }
  1320. // ExtensibleObject additionalHeader
  1321. length += extensionObject_calcSize(responseHeader->additionalHeader);
  1322. return length;
  1323. }