opcua_binaryEncDec.c 46 KB

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