opcua_basictypes.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /*
  2. * opcua_basictypes.c
  3. *
  4. * Created on: 13.03.2014
  5. * Author: mrt
  6. */
  7. #include "opcua.h"
  8. #include <stdio.h> // printf
  9. #include <stdlib.h> // alloc, free
  10. #include <string.h>
  11. Int32 UA_calcSize(void* const data, UInt32 type) {
  12. return (UA_[type].calcSize)(data);
  13. }
  14. Int32 UA_Array_calcSize(Int32 nElements, Int32 type, void const ** data) {
  15. int length = sizeof(UA_Int32);
  16. int i;
  17. if (nElements > 0) {
  18. for(i=0; i<nElements;i++,data++) {
  19. length += UA_calcSize(data,type);
  20. }
  21. }
  22. return length;
  23. }
  24. Int32 UA_Array_encode(void const **src, Int32 noElements, Int32 type, Int32* pos, char * dst) {
  25. //TODO: Implement
  26. return UA_ERR_NOT_IMPLEMENTED;
  27. }
  28. Int32 UA_Array_decode(char const * src, Int32 noElements, Int32 type, Int32* pos, void const **dst) {
  29. //TODO: Implement
  30. return UA_ERR_NOT_IMPLEMENTED;
  31. }
  32. Int32 UA_free(void * ptr){
  33. printf("UA_free - ptr=%p\n",ptr);
  34. free(ptr);
  35. return UA_SUCCESS;
  36. }
  37. Int32 UA_alloc(void ** ptr, int size){
  38. *ptr = malloc(size);
  39. printf("UA_alloc - ptr=%p, size=%d\n",*ptr,size);
  40. if(*ptr == UA_NULL) return UA_ERR_NO_MEMORY;
  41. return UA_SUCCESS;
  42. }
  43. Int32 UA_memcpy(void * dst, void const * src, int size){
  44. memcpy(dst, src, size);
  45. return UA_SUCCESS;
  46. }
  47. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Boolean)
  48. Int32 UA_Boolean_encode(UA_Boolean const * src, Int32* pos, char * dst) {
  49. UA_Boolean tmpBool = ((*src > 0) ? UA_TRUE : UA_FALSE);
  50. memcpy(&(dst[(*pos)++]), &tmpBool, sizeof(UA_Boolean));
  51. return UA_SUCCESS;
  52. }
  53. Int32 UA_Boolean_decode(char const * src, Int32* pos, UA_Boolean * dst) {
  54. *dst = ((UA_Boolean) (src[(*pos)++]) > 0) ? UA_TRUE : UA_FALSE;
  55. return UA_SUCCESS;
  56. }
  57. UA_TYPE_METHOD_DELETE_FREE(UA_Boolean)
  58. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Boolean)
  59. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Byte)
  60. Int32 UA_Byte_encode(UA_Byte const * src, Int32* pos, char * dst) {
  61. *dst = src[(*pos)++];
  62. return UA_SUCCESS;
  63. }
  64. Int32 UA_Byte_decode(char const * src, Int32* pos, UA_Byte * dst) {
  65. memcpy(&(dst[(*pos)++]), src, sizeof(UA_Byte));
  66. return UA_SUCCESS;
  67. }
  68. UA_TYPE_METHOD_DELETE_FREE(UA_Byte)
  69. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Byte)
  70. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_SByte)
  71. Int32 UA_SByte_encode(UA_SByte const * src, Int32* pos, char * dst) {
  72. dst[(*pos)++] = *src;
  73. return UA_SUCCESS;
  74. }
  75. Int32 UA_SByte_decode(char const * src, Int32* pos, UA_SByte * dst) {
  76. *dst = src[(*pos)++];
  77. return 1;
  78. }
  79. UA_TYPE_METHOD_DELETE_FREE(UA_SByte)
  80. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_SByte)
  81. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_UInt16)
  82. Int32 UA_UInt16_encode(UA_UInt16 const *src, Int32* pos, char * dst) {
  83. memcpy(&(dst[*pos]), src, sizeof(UA_UInt16));
  84. *pos += sizeof(UA_UInt16);
  85. return UA_SUCCESS;
  86. }
  87. Int32 UA_UInt16_decode(char const * src, Int32* pos, UA_UInt16* dst) {
  88. Byte t1 = src[(*pos)++];
  89. UInt16 t2 = (UInt16) (src[(*pos)++] << 8);
  90. *dst = t1 + t2;
  91. return UA_SUCCESS;
  92. }
  93. UA_TYPE_METHOD_DELETE_FREE(UA_UInt16)
  94. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_UInt16)
  95. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Int16)
  96. Int32 UA_Int16_encode(UA_Int16 const * src, Int32* pos, char* dst) {
  97. memcpy(&(dst[*pos]), src, sizeof(UA_Int16));
  98. *pos += sizeof(UA_Int16);
  99. return UA_SUCCESS;
  100. }
  101. Int32 UA_Int16_decode(char const * src, Int32* pos, UA_Int16 *dst) {
  102. Int16 t1 = (Int16) (((SByte) (src[(*pos)++]) & 0xFF));
  103. Int16 t2 = (Int16) (((SByte) (src[(*pos)++]) & 0xFF) << 8);
  104. *dst = t1 + t2;
  105. return UA_SUCCESS;
  106. }
  107. UA_TYPE_METHOD_DELETE_FREE(UA_Int16)
  108. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Int16)
  109. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Int32)
  110. Int32 UA_Int32_encode(UA_Int32 const * src, Int32* pos, char *dst) {
  111. memcpy(&(dst[*pos]), src, sizeof(UA_Int32));
  112. *pos += sizeof(UA_Int32);
  113. return UA_SUCCESS;
  114. }
  115. Int32 UA_Int32_decode(char const * src, Int32* pos, UA_Int32* dst) {
  116. Int32 t1 = (Int32) (((SByte) (src[(*pos)++]) & 0xFF));
  117. Int32 t2 = (Int32) (((SByte) (src[(*pos)++]) & 0xFF) << 8);
  118. Int32 t3 = (Int32) (((SByte) (src[(*pos)++]) & 0xFF) << 16);
  119. Int32 t4 = (Int32) (((SByte) (src[(*pos)++]) & 0xFF) << 24);
  120. *dst = t1 + t2 + t3 + t4;
  121. return UA_SUCCESS;
  122. }
  123. UA_TYPE_METHOD_DELETE_FREE(UA_Int32)
  124. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Int32)
  125. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_UInt32)
  126. Int32 UA_UInt32_encode(UA_UInt32 const * src, Int32* pos, char *dst) {
  127. memcpy(&(dst[*pos]), src, sizeof(UA_UInt32));
  128. *pos += sizeof(UA_UInt32);
  129. return UA_SUCCESS;
  130. }
  131. Int32 UA_UInt32_decode(char const * src, Int32* pos, UA_UInt32 *dst) {
  132. UInt32 t1 = (UInt32) src[(*pos)++];
  133. UInt32 t2 = (UInt32) src[(*pos)++] << 8;
  134. UInt32 t3 = (UInt32) src[(*pos)++] << 16;
  135. UInt32 t4 = (UInt32) src[(*pos)++] << 24;
  136. *dst = t1 + t2 + t3 + t4;
  137. return UA_SUCCESS;
  138. }
  139. UA_TYPE_METHOD_DELETE_FREE(UA_UInt32)
  140. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_UInt32)
  141. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Int64)
  142. Int32 UA_Int64_encode(UA_Int64 const * src, Int32* pos, char *dst) {
  143. memcpy(&(dst[*pos]), src, sizeof(UA_Int64));
  144. *pos += sizeof(UA_Int64);
  145. return UA_SUCCESS;
  146. }
  147. Int32 UA_Int64_decode(char const * src, Int32* pos, UA_Int64* dst) {
  148. Int64 t1 = (Int64) src[(*pos)++];
  149. Int64 t2 = (Int64) src[(*pos)++] << 8;
  150. Int64 t3 = (Int64) src[(*pos)++] << 16;
  151. Int64 t4 = (Int64) src[(*pos)++] << 24;
  152. Int64 t5 = (Int64) src[(*pos)++] << 32;
  153. Int64 t6 = (Int64) src[(*pos)++] << 40;
  154. Int64 t7 = (Int64) src[(*pos)++] << 48;
  155. Int64 t8 = (Int64) src[(*pos)++] << 56;
  156. *dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
  157. return UA_SUCCESS;
  158. }
  159. UA_TYPE_METHOD_DELETE_FREE(UA_Int64)
  160. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Int64)
  161. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_UInt64)
  162. Int32 UA_UInt64_encode(UA_UInt64 const * src , Int32* pos, char * dst) {
  163. memcpy(&(dst[*pos]), src, sizeof(UA_UInt64));
  164. *pos += sizeof(UInt64);
  165. return UA_SUCCESS;
  166. }
  167. Int32 UA_UInt64_decode(char const * src, Int32* pos, UA_UInt64* dst) {
  168. UInt64 t1 = (UInt64) src[(*pos)++];
  169. UInt64 t2 = (UInt64) src[(*pos)++] << 8;
  170. UInt64 t3 = (UInt64) src[(*pos)++] << 16;
  171. UInt64 t4 = (UInt64) src[(*pos)++] << 24;
  172. UInt64 t5 = (UInt64) src[(*pos)++] << 32;
  173. UInt64 t6 = (UInt64) src[(*pos)++] << 40;
  174. UInt64 t7 = (UInt64) src[(*pos)++] << 48;
  175. UInt64 t8 = (UInt64) src[(*pos)++] << 56;
  176. *dst = t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8;
  177. return UA_SUCCESS;
  178. }
  179. UA_TYPE_METHOD_DELETE_FREE(UA_UInt64)
  180. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_UInt64)
  181. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Float)
  182. Int32 UA_Float_decode(char const * src, Int32* pos, UA_Float* dst) {
  183. // TODO: not yet implemented
  184. memcpy(dst, &(src[*pos]), sizeof(UA_Float));
  185. *pos += sizeof(UA_Float);
  186. return UA_SUCCESS;
  187. }
  188. Int32 UA_Float_encode(UA_Float const * src, Int32* pos, char *dst) {
  189. // TODO: not yet implemented
  190. memcpy(&(dst[*pos]), src, sizeof(UA_Float));
  191. *pos += sizeof(UA_Float);
  192. return UA_SUCCESS;
  193. }
  194. UA_TYPE_METHOD_DELETE_FREE(UA_Float)
  195. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Float)
  196. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_Double)
  197. Int32 UA_Double_decode(char const * src, Int32* pos, UA_Double * dst) {
  198. // TODO: not yet implemented
  199. Double tmpDouble;
  200. tmpDouble = (Double) (src[*pos]);
  201. *pos += sizeof(UA_Double);
  202. *dst = tmpDouble;
  203. return UA_SUCCESS;
  204. }
  205. Int32 UA_Double_encode(UA_Double const * src, Int32 *pos, char * dst) {
  206. // TODO: not yet implemented
  207. memcpy(&(dst[*pos]), src, sizeof(UA_Double));
  208. *pos *= sizeof(UA_Double);
  209. return UA_SUCCESS;
  210. }
  211. UA_TYPE_METHOD_DELETE_FREE(UA_Double)
  212. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_Double)
  213. Int32 UA_String_calcSize(UA_String const * string) {
  214. if (string == UA_NULL) {
  215. // internal size for UA_memalloc
  216. return sizeof(UA_String);
  217. } else {
  218. // binary encoding size
  219. if (string->length > 0) {
  220. return sizeof(UA_Int32) + string->length * sizeof(UA_Byte);
  221. } else {
  222. return sizeof(UA_Int32);
  223. }
  224. }
  225. }
  226. Int32 UA_String_encode(UA_String const * src, Int32* pos, char *dst) {
  227. UA_Int32_encode(&(src->length),pos,dst);
  228. if (src->length > 0) {
  229. UA_memcpy((void*)&(dst[*pos]), src->data, src->length);
  230. *pos += src->length;
  231. }
  232. return UA_SUCCESS;
  233. }
  234. Int32 UA_String_decode(char const * src, Int32* pos, UA_String * dst) {
  235. Int32 retval = UA_SUCCESS;
  236. retval |= UA_Int32_decode(src,pos,&(dst->length));
  237. if (dst->length > 0) {
  238. retval |= UA_alloc((void**)&(dst->data),dst->length);
  239. retval |= UA_memcpy((void*)&(src[*pos]),dst->data,dst->length);
  240. *pos += dst->length;
  241. } else {
  242. dst->data = UA_NULL;
  243. }
  244. return retval;
  245. }
  246. UA_TYPE_METHOD_DELETE_STRUCT(UA_String)
  247. Int32 UA_String_deleteMembers(UA_String* p) { return UA_free(p->data); }
  248. Int32 UA_String_copy(UA_String const * src, UA_String* dst) {
  249. Int32 retval = UA_SUCCESS;
  250. dst->length = src->length;
  251. dst->data = UA_NULL;
  252. if (src->length > 0) {
  253. retval |= UA_alloc((void**)&(dst->data), src->length);
  254. if (retval == UA_SUCCESS) {
  255. retval |= UA_memcpy((void*)dst->data, src->data, src->length);
  256. }
  257. }
  258. return retval;
  259. }
  260. UA_String UA_String_null = { -1, UA_NULL };
  261. UA_Byte UA_Byte_securityPoliceNoneData[] = "http://opcfoundation.org/UA/SecurityPolicy#None";
  262. UA_String UA_String_securityPoliceNone = { sizeof(UA_Byte_securityPoliceNoneData), UA_Byte_securityPoliceNoneData };
  263. // TODO: should we really handle UA_String and UA_ByteString the same way?
  264. UA_TYPE_METHOD_CALCSIZE_AS(UA_ByteString, UA_String)
  265. UA_TYPE_METHOD_ENCODE_AS(UA_ByteString, UA_String)
  266. UA_TYPE_METHOD_DECODE_AS(UA_ByteString, UA_String)
  267. UA_TYPE_METHOD_DELETE_AS(UA_ByteString, UA_String)
  268. UA_TYPE_METHOD_DELETEMEMBERS_AS(UA_ByteString, UA_String)
  269. Int32 UA_Guid_calcSize(UA_Guid const * p) {
  270. if (p == UA_NULL) {
  271. return sizeof(UA_Guid);
  272. } else {
  273. return 0
  274. + sizeof(p->data1)
  275. + sizeof(p->data2)
  276. + sizeof(p->data3)
  277. + UA_ByteString_calcSize(&(p->data4))
  278. ;
  279. }
  280. }
  281. Int32 UA_Guid_encode(UA_Guid const *src, Int32* pos, char *dst) {
  282. Int32 retval = UA_SUCCESS;
  283. retval |= UA_UInt32_encode(&(src->data1), pos, dst);
  284. retval |= UA_UInt16_encode(&(src->data2), pos, dst);
  285. retval |= UA_UInt16_encode(&(src->data3), pos, dst);
  286. retval |= UA_ByteString_encode(&(src->data4), pos, dst);
  287. return UA_SUCCESS;
  288. }
  289. Int32 UA_Guid_decode(char const * src, Int32* pos, UA_Guid *dst) {
  290. Int32 retval = UA_SUCCESS;
  291. retval |= UA_UInt32_decode(src,pos,&(dst->data1));
  292. retval |= UA_UInt16_decode(src,pos,&(dst->data2));
  293. retval |= UA_UInt16_decode(src,pos,&(dst->data3));
  294. retval |= UA_ByteString_decode(src,pos,&(dst->data4));
  295. return retval;
  296. }
  297. UA_TYPE_METHOD_DELETE_STRUCT(UA_Guid)
  298. Int32 UA_Guid_deleteMembers(UA_Guid* p) { return UA_ByteString_delete(&(p->data4)); }
  299. Int32 UA_LocalizedText_calcSize(UA_LocalizedText const * p) {
  300. Int32 length = 0;
  301. if (p==UA_NULL) {
  302. // size for UA_memalloc
  303. length = sizeof(UA_LocalizedText);
  304. } else {
  305. // size for binary encoding
  306. length += p->encodingMask;
  307. if (p->encodingMask & 0x01) {
  308. length += UA_String_calcSize(&(p->locale));
  309. }
  310. if (p->encodingMask & 0x02) {
  311. length += UA_String_calcSize(&(p->text));
  312. }
  313. }
  314. return length;
  315. }
  316. Int32 UA_LocalizedText_encode(UA_LocalizedText const * src, Int32 *pos,
  317. char * dst) {
  318. Int32 retval = UA_SUCCESS;
  319. retval |= UA_Byte_encode(&(src->encodingMask),pos,dst);
  320. if (src->encodingMask & 0x01) {
  321. UA_String_encode(&(src->locale),pos,dst);
  322. }
  323. if (src->encodingMask & 0x02) {
  324. UA_String_encode(&(src->text),pos,dst);
  325. }
  326. return retval;
  327. }
  328. Int32 UA_LocalizedText_decode(char const * src, Int32 *pos,
  329. UA_LocalizedText *dst) {
  330. Int32 retval = UA_SUCCESS;
  331. retval |= UA_String_copy(&UA_String_null,&(dst->locale));
  332. retval |= UA_String_copy(&UA_String_null,&(dst->text));
  333. retval |= UA_Byte_decode(src,pos,&(dst->encodingMask));
  334. if (dst->encodingMask & 0x01) {
  335. retval |= UA_String_decode(src,pos,&(dst->locale));
  336. }
  337. if (dst->encodingMask & 0x02) {
  338. retval |= UA_String_decode(src,pos,&(dst->text));
  339. }
  340. return retval;
  341. }
  342. UA_TYPE_METHOD_DELETE_STRUCT(UA_LocalizedText)
  343. Int32 UA_LocalizedText_deleteMembers(UA_LocalizedText* p) {
  344. return UA_SUCCESS
  345. || UA_String_deleteMembers(&(p->locale))
  346. || UA_String_deleteMembers(&(p->text))
  347. ;
  348. }
  349. /* Serialization of UA_NodeID is specified in 62541-6, §5.2.2.9 */
  350. Int32 UA_NodeId_calcSize(UA_NodeId const *p) {
  351. Int32 length = 0;
  352. if (p == UA_NULL) {
  353. length = sizeof(UA_NodeId);
  354. } else {
  355. switch (p->encodingByte) {
  356. case UA_NodeIdType_TwoByte:
  357. length += 2 * sizeof(UA_Byte);
  358. break;
  359. case UA_NodeIdType_FourByte:
  360. length += 4 * sizeof(UA_Byte);
  361. break;
  362. case UA_NodeIdType_Numeric:
  363. length += sizeof(UA_Byte) + sizeof(UA_UInt16) + sizeof(UInt32);
  364. break;
  365. case UA_NodeIdType_String:
  366. length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_String_calcSize(&(p->identifier.string));
  367. break;
  368. case UA_NodeIdType_Guid:
  369. length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_Guid_calcSize(&(p->identifier.guid));
  370. break;
  371. case UA_NodeIdType_ByteString:
  372. length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_ByteString_calcSize(&(p->identifier.byteString));
  373. break;
  374. default:
  375. break;
  376. }
  377. }
  378. return length;
  379. }
  380. Int32 UA_NodeId_encode(UA_NodeId const * src, Int32* pos, char *dst) {
  381. // temporary variables for endian-save code
  382. UA_Byte srcByte;
  383. UA_UInt16 srcUInt16;
  384. int retval = UA_SUCCESS;
  385. retval |= UA_Byte_encode(&(src->encodingByte),pos,dst);
  386. switch (src->encodingByte) {
  387. case UA_NodeIdType_TwoByte:
  388. srcByte = src->identifier.numeric;
  389. retval |= UA_Byte_encode(&srcByte,pos,dst);
  390. break;
  391. case UA_NodeIdType_FourByte:
  392. srcByte = src->namespace;
  393. srcUInt16 = src->identifier.numeric;
  394. retval |= UA_Byte_encode(&srcByte,pos,dst);
  395. retval |= UA_UInt16_encode(&srcUInt16,pos,dst);
  396. break;
  397. case UA_NodeIdType_Numeric:
  398. retval |= UA_UInt16_encode(&(src->namespace), pos, dst);
  399. retval |= UA_UInt32_encode(&(src->identifier.numeric), pos, dst);
  400. break;
  401. case UA_NodeIdType_String:
  402. retval |= UA_UInt16_encode(&(src->namespace), pos, dst);
  403. retval |= UA_String_encode(&(src->identifier.string), pos, dst);
  404. break;
  405. case UA_NodeIdType_Guid:
  406. retval |= UA_UInt16_encode(&(src->namespace), pos, dst);
  407. retval |= UA_Guid_encode(&(src->identifier.guid), pos, dst);
  408. break;
  409. case UA_NodeIdType_ByteString:
  410. retval |= UA_UInt16_encode(&(src->namespace), pos, dst);
  411. retval |= UA_ByteString_encode(&(src->identifier.byteString), pos, dst);
  412. break;
  413. }
  414. return retval;
  415. }
  416. Int32 UA_NodeId_decode(char const * src, Int32* pos, UA_NodeId *dst) {
  417. int retval = UA_SUCCESS;
  418. // temporary variables to overcome decoder's non-endian-saveness for datatypes
  419. UA_Byte dstByte;
  420. UA_UInt16 dstUInt16;
  421. retval |= UA_Byte_decode(src,pos,&(dst->encodingByte));
  422. switch (dst->encodingByte) {
  423. case UA_NodeIdType_TwoByte: // Table 7
  424. retval |=UA_Byte_decode(src, pos, &dstByte);
  425. dst->identifier.numeric = dstByte;
  426. dst->namespace = 0; // default namespace
  427. break;
  428. case UA_NodeIdType_FourByte: // Table 8
  429. retval |=UA_Byte_decode(src, pos, &dstByte);
  430. dst->namespace= dstByte;
  431. retval |=UA_UInt16_decode(src, pos, &dstUInt16);
  432. dst->identifier.numeric = dstUInt16;
  433. break;
  434. case UA_NodeIdType_Numeric: // Table 6, first entry
  435. retval |=UA_UInt16_decode(src,pos,&(dst->namespace));
  436. retval |=UA_UInt32_decode(src,pos,&(dst->identifier.numeric));
  437. break;
  438. case UA_NodeIdType_String: // Table 6, second entry
  439. retval |=UA_UInt16_decode(src,pos,&(dst->namespace));
  440. retval |=UA_String_decode(src,pos,&(dst->identifier.string));
  441. break;
  442. case UA_NodeIdType_Guid: // Table 6, third entry
  443. retval |=UA_UInt16_decode(src,pos,&(dst->namespace));
  444. retval |=UA_Guid_decode(src,pos,&(dst->identifier.guid));
  445. break;
  446. case UA_NodeIdType_ByteString: // Table 6, "OPAQUE"
  447. retval |=UA_UInt16_decode(src,pos,&(dst->namespace));
  448. retval |=UA_ByteString_decode(src,pos,&(dst->identifier.byteString));
  449. break;
  450. }
  451. return retval;
  452. }
  453. UA_TYPE_METHOD_DELETE_STRUCT(UA_NodeId)
  454. Int32 UA_NodeId_deleteMembers(UA_NodeId* p) {
  455. int retval = UA_SUCCESS;
  456. switch (p->encodingByte) {
  457. case UA_NodeIdType_TwoByte:
  458. case UA_NodeIdType_FourByte:
  459. case UA_NodeIdType_Numeric:
  460. // nothing to do
  461. break;
  462. case UA_NodeIdType_String: // Table 6, second entry
  463. retval |= UA_String_deleteMembers(&(p->identifier.string));
  464. break;
  465. case UA_NodeIdType_Guid: // Table 6, third entry
  466. retval |= UA_Guid_deleteMembers(&(p->identifier.guid));
  467. break;
  468. case UA_NodeIdType_ByteString: // Table 6, "OPAQUE"
  469. retval |= UA_ByteString_deleteMembers(&(p->identifier.byteString));
  470. break;
  471. }
  472. return retval;
  473. }
  474. //FIXME: Sten Where do these two flags come from?
  475. #define NIEVT_NAMESPACE_URI_FLAG 0x80 //Is only for ExpandedNodeId required
  476. #define NIEVT_SERVERINDEX_FLAG 0x40 //Is only for ExpandedNodeId required
  477. Int32 UA_ExpandedNodeId_calcSize(UA_ExpandedNodeId const * p) {
  478. Int32 length = 0;
  479. if (p == UA_NULL) {
  480. length = sizeof(UA_ExpandedNodeId);
  481. } else {
  482. length = UA_NodeId_calcSize(&(p->nodeId));
  483. if (p->nodeId.encodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  484. length += UA_String_calcSize(&(p->namespaceUri)); //p->namespaceUri
  485. }
  486. if (p->nodeId.encodingByte & NIEVT_SERVERINDEX_FLAG) {
  487. length += sizeof(UA_UInt32); //p->serverIndex
  488. }
  489. }
  490. return length;
  491. }
  492. Int32 UA_ExpandedNodeId_encode(UA_ExpandedNodeId const * src, Int32* pos, char *dst) {
  493. UInt32 retval = UA_SUCCESS;
  494. retval |= UA_NodeId_encode(&(src->nodeId),pos,dst);
  495. if (src->nodeId.encodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  496. retval |= UA_String_encode(&(src->namespaceUri),pos,dst);
  497. }
  498. if (src->nodeId.encodingByte & NIEVT_SERVERINDEX_FLAG) {
  499. retval |= UA_UInt32_encode(&(src->serverIndex),pos,dst);
  500. }
  501. return retval;
  502. }
  503. Int32 UA_ExpandedNodeId_decode(char const * src, Int32* pos,
  504. UA_ExpandedNodeId *dst) {
  505. UInt32 retval = UA_SUCCESS;
  506. retval |= UA_NodeId_decode(src,pos,&(dst->nodeId));
  507. if (dst->nodeId.encodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  508. dst->nodeId.namespace = 0;
  509. retval |= UA_String_decode(src,pos,&(dst->namespaceUri));
  510. } else {
  511. retval |= UA_String_copy(&UA_String_null, &(dst->namespaceUri));
  512. }
  513. if (dst->nodeId.encodingByte & NIEVT_SERVERINDEX_FLAG) {
  514. retval |= UA_UInt32_decode(src,pos,&(dst->serverIndex));
  515. }
  516. return retval;
  517. }
  518. UA_TYPE_METHOD_DELETE_STRUCT(UA_ExpandedNodeId)
  519. Int32 UA_ExpandedNodeId_deleteMembers(UA_ExpandedNodeId* p) {
  520. Int32 retval = UA_SUCCESS;
  521. retval |= UA_NodeId_deleteMembers(&(p->nodeId));
  522. retval |= UA_String_deleteMembers(&(p->namespaceUri));
  523. return retval;
  524. }
  525. Int32 UA_ExtensionObject_calcSize(UA_ExtensionObject const * p) {
  526. Int32 length = 0;
  527. if (p == UA_NULL) {
  528. length = sizeof(UA_ExtensionObject);
  529. } else {
  530. length += UA_NodeId_calcSize(&(p->typeId));
  531. length += sizeof(Byte); //p->encoding
  532. switch (p->encoding) {
  533. case 0x00:
  534. length += sizeof(UA_Int32); //p->body.length
  535. break;
  536. case 0x01:
  537. length += UA_ByteString_calcSize(&(p->body));
  538. break;
  539. case 0x02:
  540. length += UA_ByteString_calcSize(&(p->body));
  541. break;
  542. }
  543. }
  544. return length;
  545. }
  546. Int32 UA_ExtensionObject_encode(UA_ExtensionObject const *src, Int32* pos, char * dst) {
  547. Int32 retval = UA_SUCCESS;
  548. retval |= UA_NodeId_encode(&(src->typeId),pos,dst);
  549. retval |= UA_Byte_encode(&(src->encoding),pos,dst);
  550. switch (src->encoding) {
  551. case NO_BODY_IS_ENCODED:
  552. break;
  553. case BODY_IS_BYTE_STRING:
  554. case BODY_IS_XML_ELEMENT:
  555. retval |= UA_ByteString_encode(&(src->body),pos,dst);
  556. break;
  557. }
  558. return retval;
  559. }
  560. Int32 UA_ExtensionObject_decode(char const * src, Int32 *pos,
  561. UA_ExtensionObject *dst) {
  562. Int32 retval = UA_SUCCESS;
  563. retval |= UA_NodeId_decode(src,pos,&(dst->typeId));
  564. retval |= UA_Byte_decode(src,pos,&(dst->encoding));
  565. retval |= UA_String_copy(&UA_String_null, (UA_String*) &(dst->body));
  566. switch (dst->encoding) {
  567. case NO_BODY_IS_ENCODED:
  568. break;
  569. case BODY_IS_BYTE_STRING:
  570. case BODY_IS_XML_ELEMENT:
  571. retval |= UA_ByteString_decode(src,pos,&(dst->body));
  572. break;
  573. }
  574. return retval;
  575. }
  576. UA_TYPE_METHOD_DELETE_STRUCT(UA_ExtensionObject)
  577. Int32 UA_ExtensionObject_deleteMembers(UA_ExtensionObject *p) {
  578. Int32 retval = UA_SUCCESS;
  579. retval |= UA_NodeId_deleteMembers(&(p->typeId));
  580. retval |= UA_ByteString_deleteMembers(&(p->body));
  581. return retval;
  582. }
  583. // TODO: UA_DataValue_encode
  584. // TODO: UA_DataValue_decode
  585. // TODO: UA_DataValue_delete
  586. // TODO: UA_DataValue_deleteMembers
  587. /** DiagnosticInfo - Part: 4, Chapter: 7.9, Page: 116 */
  588. Int32 UA_DiagnosticInfo_decode(char const * src, Int32 *pos, UA_DiagnosticInfo *dst) {
  589. Int32 retval = UA_SUCCESS;
  590. int i;
  591. retval |= UA_Byte_decode(src, pos, &(dst->encodingMask));
  592. for (i = 0; i < 7; i++) {
  593. switch ( (0x01 << i) & dst->encodingMask) {
  594. case DIEMT_SYMBOLIC_ID:
  595. retval |= UA_Int32_decode(src, pos, &(dst->symbolicId));
  596. break;
  597. case DIEMT_NAMESPACE:
  598. retval |= UA_Int32_decode(src, pos, &(dst->namespaceUri));
  599. break;
  600. case DIEMT_LOCALIZED_TEXT:
  601. retval |= UA_Int32_decode(src, pos, &(dst->localizedText));
  602. break;
  603. case DIEMT_LOCALE:
  604. retval |= UA_Int32_decode(src, pos, &(dst->locale));
  605. break;
  606. case DIEMT_ADDITIONAL_INFO:
  607. retval |= UA_String_decode(src, pos, &(dst->additionalInfo));
  608. break;
  609. case DIEMT_INNER_STATUS_CODE:
  610. retval |= UA_StatusCode_decode(src, pos, &(dst->innerStatusCode));
  611. break;
  612. case DIEMT_INNER_DIAGNOSTIC_INFO:
  613. // innerDiagnosticInfo is a pointer to struct, therefore allocate
  614. retval |= UA_alloc((void **) &(dst->innerDiagnosticInfo),UA_DiagnosticInfo_calcSize(UA_NULL));
  615. retval |= UA_DiagnosticInfo_decode(src, pos, dst->innerDiagnosticInfo);
  616. break;
  617. }
  618. }
  619. return retval;
  620. }
  621. Int32 UA_DiagnosticInfo_encode(UA_DiagnosticInfo const *src, Int32 *pos, char *dst) {
  622. Int32 retval = UA_SUCCESS;
  623. Byte mask;
  624. int i;
  625. UA_Byte_encode(&(src->encodingMask), pos, dst);
  626. for (i = 0; i < 7; i++) {
  627. switch ( (0x01 << i) & src->encodingMask) {
  628. case DIEMT_SYMBOLIC_ID:
  629. retval |= UA_Int32_encode(&(src->symbolicId), pos, dst);
  630. break;
  631. case DIEMT_NAMESPACE:
  632. retval |= UA_Int32_encode( &(src->namespaceUri), pos, dst);
  633. break;
  634. case DIEMT_LOCALIZED_TEXT:
  635. retval |= UA_Int32_encode(&(src->localizedText), pos, dst);
  636. break;
  637. case DIEMT_LOCALE:
  638. retval |= UA_Int32_encode(&(src->locale), pos, dst);
  639. break;
  640. case DIEMT_ADDITIONAL_INFO:
  641. retval |= UA_String_encode(&(src->additionalInfo), pos, dst);
  642. break;
  643. case DIEMT_INNER_STATUS_CODE:
  644. retval |= UA_StatusCode_encode(&(src->innerStatusCode), pos, dst);
  645. break;
  646. case DIEMT_INNER_DIAGNOSTIC_INFO:
  647. retval |= UA_DiagnosticInfo_encode(src->innerDiagnosticInfo, pos, dst);
  648. break;
  649. }
  650. }
  651. return retval;
  652. }
  653. Int32 UA_DiagnosticInfo_calcSize(UA_DiagnosticInfo const * ptr) {
  654. Int32 length = 0;
  655. if (ptr == UA_NULL) {
  656. length = sizeof(UA_DiagnosticInfo);
  657. } else {
  658. Byte mask;
  659. length += sizeof(Byte); // EncodingMask
  660. for (mask = 0x01; mask <= 0x40; mask *= 2) {
  661. switch (mask & (ptr->encodingMask)) {
  662. case DIEMT_SYMBOLIC_ID:
  663. // puts("diagnosticInfo symbolic id");
  664. length += sizeof(UA_Int32);
  665. break;
  666. case DIEMT_NAMESPACE:
  667. length += sizeof(UA_Int32);
  668. break;
  669. case DIEMT_LOCALIZED_TEXT:
  670. length += sizeof(UA_Int32);
  671. break;
  672. case DIEMT_LOCALE:
  673. length += sizeof(UA_Int32);
  674. break;
  675. case DIEMT_ADDITIONAL_INFO:
  676. length += UA_String_calcSize(&(ptr->additionalInfo));
  677. break;
  678. case DIEMT_INNER_STATUS_CODE:
  679. length += sizeof(UA_StatusCode);
  680. break;
  681. case DIEMT_INNER_DIAGNOSTIC_INFO:
  682. length += UA_DiagnosticInfo_calcSize(ptr->innerDiagnosticInfo);
  683. break;
  684. }
  685. }
  686. }
  687. return length;
  688. }
  689. UA_TYPE_METHOD_DELETE_STRUCT(UA_DiagnosticInfo)
  690. Int32 UA_DiagnosticInfo_deleteMembers(UA_DiagnosticInfo *p) {
  691. Int32 retval = UA_SUCCESS;
  692. if (p->encodingMask & DIEMT_INNER_DIAGNOSTIC_INFO) {
  693. retval |= UA_DiagnosticInfo_deleteMembers(p->innerDiagnosticInfo);
  694. retval |= UA_free(p->innerDiagnosticInfo);
  695. }
  696. return retval;
  697. }
  698. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_DateTime)
  699. UA_TYPE_METHOD_ENCODE_AS(UA_DateTime,UA_Int64)
  700. UA_TYPE_METHOD_DECODE_AS(UA_DateTime,UA_Int64)
  701. UA_TYPE_METHOD_DELETE_FREE(UA_DateTime)
  702. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_DateTime)
  703. UA_TYPE_METHOD_CALCSIZE_AS(UA_XmlElement, UA_ByteString)
  704. UA_TYPE_METHOD_ENCODE_AS(UA_XmlElement, UA_ByteString)
  705. UA_TYPE_METHOD_DECODE_AS(UA_XmlElement, UA_ByteString)
  706. UA_TYPE_METHOD_DELETE_AS(UA_XmlElement, UA_ByteString)
  707. UA_TYPE_METHOD_DELETEMEMBERS_AS(UA_XmlElement, UA_ByteString)
  708. /** IntegerId - Part: 4, Chapter: 7.13, Page: 118 */
  709. UA_TYPE_METHOD_CALCSIZE_AS(UA_IntegerId, UA_Int32)
  710. UA_TYPE_METHOD_ENCODE_AS(UA_IntegerId, UA_Int32)
  711. UA_TYPE_METHOD_DECODE_AS(UA_IntegerId, UA_Int32)
  712. UA_TYPE_METHOD_DELETE_AS(UA_IntegerId, UA_Int32)
  713. UA_TYPE_METHOD_DELETEMEMBERS_AS(UA_IntegerId, UA_Int32)
  714. UA_TYPE_METHOD_CALCSIZE_AS(UA_StatusCode, UA_UInt32)
  715. UA_TYPE_METHOD_ENCODE_AS(UA_StatusCode, UA_UInt32)
  716. UA_TYPE_METHOD_DECODE_AS(UA_StatusCode, UA_UInt32)
  717. UA_TYPE_METHOD_DELETE_AS(UA_StatusCode, UA_UInt32)
  718. UA_TYPE_METHOD_DELETEMEMBERS_AS(UA_StatusCode, UA_UInt32)
  719. Int32 UA_QualifiedName_calcSize(UA_QualifiedName const * p) {
  720. Int32 length = 0;
  721. length += sizeof(UInt16); //qualifiedName->namespaceIndex
  722. length += sizeof(UInt16); //qualifiedName->reserved
  723. length += UA_String_calcSize(&(p->name)); //qualifiedName->name
  724. return length;
  725. }
  726. Int32 UA_QualifiedName_decode(char const * src, Int32 *pos,
  727. UA_QualifiedName *dst) {
  728. Int32 retval = UA_SUCCESS;
  729. retval |= UA_UInt16_decode(src,pos,&(dst->namespaceIndex));
  730. retval |= UA_UInt16_decode(src,pos,&(dst->reserved));
  731. retval |= UA_String_decode(src,pos,&(dst->name));
  732. return retval;
  733. }
  734. Int32 UA_QualifiedName_encode(UA_QualifiedName const *src, Int32* pos,
  735. char *dst) {
  736. Int32 retval = UA_SUCCESS;
  737. retval |= UA_UInt16_encode(&(src->namespaceIndex),pos,dst);
  738. retval |= UA_UInt16_encode(&(src->reserved),pos,dst);
  739. retval |= UA_String_encode(&(src->name),pos,dst);
  740. return retval;
  741. }
  742. Int32 UA_Variant_calcSize(UA_Variant const * p) {
  743. Int32 length = 0;
  744. Int32 ns0Id = p->encodingMask & 0x1F; // Bits 1-5
  745. Boolean isArray = p->encodingMask & (0x01 << 7); // Bit 7
  746. Boolean hasDimensions = p->encodingMask & (0x01 << 6); // Bit 6
  747. int i;
  748. if (p->vt == UA_NULL || p->encodingMask != p->vt->Id) {
  749. return UA_ERR_INCONSISTENT;
  750. }
  751. length += sizeof(Byte); //p->encodingMask
  752. if (isArray) { // array length is encoded
  753. length += sizeof(Int32); //p->arrayLength
  754. if (p->arrayLength > 0) {
  755. // TODO: add suggestions of @jfpr to not iterate over arrays with fixed len elements
  756. for (i=0;i<p->arrayLength;i++) {
  757. length += p->vt->calcSize(p->data[i]);
  758. }
  759. }
  760. } else { //single value to encode
  761. length += p->vt->calcSize(p->data[0]);
  762. }
  763. if (hasDimensions) {
  764. //ToDo: tobeInsert: length += the calcSize for dimensions
  765. }
  766. return length;
  767. }
  768. Int32 UA_Variant_encode(UA_Variant const *src, Int32* pos, char *dst) {
  769. Int32 retval = UA_SUCCESS;
  770. int i;
  771. if (src->vt == UA_NULL || src->encodingMask != src->vt->Id) {
  772. return UA_ERR_INCONSISTENT;
  773. }
  774. retval |= UA_Byte_encode(&(src->encodingMask),pos,dst);
  775. if (src->encodingMask & (0x01 << 7)) { // encode array length
  776. retval |= UA_Int32_encode(&(src->arrayLength),pos,dst);
  777. }
  778. if (src->arrayLength > 0) {
  779. //encode array as given by variant type
  780. for (i=0;i<src->arrayLength;i++) {
  781. retval |= src->vt->encode(src->data[i],pos,dst);
  782. }
  783. } else {
  784. retval |= src->vt->encode(src->data[i],pos,dst);
  785. }
  786. if (src->encodingMask & (1 << 6)) { // encode array dimension field
  787. // TODO: encode array dimension field
  788. }
  789. return retval;
  790. }
  791. Int32 UA_Variant_decode(char const * src, Int32 *pos, UA_Variant *dst) {
  792. Int32 retval = UA_SUCCESS;
  793. Int32 ns0Id;
  794. int i;
  795. retval |= UA_Byte_decode(src,pos,&(dst->encodingMask));
  796. ns0Id = dst->encodingMask & 0x1F;
  797. // initialize vTable
  798. if (ns0Id < UA_BOOLEAN && ns0Id > UA_DOUBLECOMPLEXNUMBERTYPE) {
  799. return UA_ERR_INVALID_VALUE;
  800. } else {
  801. dst->vt = &UA_[UA_toIndex(ns0Id)];
  802. }
  803. // get size of array
  804. if (dst->encodingMask & (0x01 << 7)) { // encode array length
  805. retval |= UA_Int32_decode(src,pos,&(dst->arrayLength));
  806. } else {
  807. dst->arrayLength = 1;
  808. }
  809. // allocate place for arrayLength pointers to any type
  810. retval |= UA_alloc(dst->data,dst->arrayLength * sizeof(void*));
  811. for (i=0;i<dst->arrayLength;i++) {
  812. // TODO: this is crazy, how to work with variants with variable size?
  813. // actually we have two different sizes - the storage size without
  814. // dynamic members and the storage size with the dynamic members, e.g.
  815. // for a string we here need to allocate definitely 8 byte (length=4, data*=4)
  816. // on a 32-bit architecture - so this code is definitely wrong
  817. retval |= UA_alloc(&(dst->data[i]),dst->vt->calcSize(UA_NULL));
  818. retval |= dst->vt->decode(src,pos,dst->data[i]);
  819. }
  820. if (dst->encodingMask & (1 << 6)) {
  821. // TODO: decode array dimension field
  822. }
  823. return retval;
  824. }
  825. //TODO: place this define at the server configuration
  826. #define MAX_PICO_SECONDS 1000
  827. Int32 UA_DataValue_decode(char const * src, Int32* pos, UA_DataValue* dst) {
  828. Int32 retval = UA_SUCCESS;
  829. retval |= UA_Byte_decode(src,pos,&(dst->encodingMask));
  830. if (dst->encodingMask & 0x01) {
  831. retval |= UA_Variant_decode(src,pos,&(dst->value));
  832. }
  833. if (dst->encodingMask & 0x02) {
  834. retval |= UA_StatusCode_decode(src,pos,&(dst->status));
  835. }
  836. if (dst->encodingMask & 0x04) {
  837. retval |= UA_DateTime_decode(src,pos,&(dst->sourceTimestamp));
  838. }
  839. if (dst->encodingMask & 0x08) {
  840. retval |= UA_DateTime_decode(src,pos,&(dst->serverTimestamp));
  841. }
  842. if (dst->encodingMask & 0x10) {
  843. retval |= UA_Int16_decode(src,pos,&(dst->sourcePicoseconds));
  844. if (dst->sourcePicoseconds > MAX_PICO_SECONDS) {
  845. dst->sourcePicoseconds = MAX_PICO_SECONDS;
  846. }
  847. }
  848. if (dst->encodingMask & 0x20) {
  849. retval |= UA_Int16_decode(src,pos,&(dst->serverPicoseconds));
  850. if (dst->serverPicoseconds > MAX_PICO_SECONDS) {
  851. dst->serverPicoseconds = MAX_PICO_SECONDS;
  852. }
  853. }
  854. return retval;
  855. }
  856. Int32 UA_DataValue_encode(UA_DataValue const * src, Int32* pos, char *dst) {
  857. Int32 retval = UA_SUCCESS;
  858. retval |= UA_Byte_encode(&(src->encodingMask),pos,dst);
  859. if (src->encodingMask & 0x01) {
  860. retval |= UA_Variant_encode(&(src->value),pos,dst);
  861. }
  862. if (src->encodingMask & 0x02) {
  863. retval |= UA_StatusCode_encode(&(src->status),pos,dst);
  864. }
  865. if (src->encodingMask & 0x04) {
  866. retval |= UA_DateTime_encode(&(src->sourceTimestamp),pos,dst);
  867. }
  868. if (src->encodingMask & 0x08) {
  869. retval |= UA_DateTime_encode(&(src->serverTimestamp),pos,dst);
  870. }
  871. if (src->encodingMask & 0x10) {
  872. retval |= UA_Int16_encode(&(src->sourcePicoseconds),pos,dst);
  873. }
  874. if (src->encodingMask & 0x10) {
  875. retval |= UA_Int16_encode(&(src->serverPicoseconds),pos,dst);
  876. }
  877. return retval;
  878. }
  879. Int32 UA_DataValue_calcSize(UA_DataValue const * p) {
  880. Int32 length = 0;
  881. if (p == UA_NULL) { // get static storage size
  882. length = sizeof(UA_DataValue);
  883. } else { // get decoding size
  884. length = sizeof(UA_Byte);
  885. if (p->encodingMask & 0x01) {
  886. length += UA_Variant_calcSize(&(p->value));
  887. }
  888. if (p->encodingMask & 0x02) {
  889. length += sizeof(UInt32); //dataValue->status
  890. }
  891. if (p->encodingMask & 0x04) {
  892. length += sizeof(Int64); //dataValue->sourceTimestamp
  893. }
  894. if (p->encodingMask & 0x08) {
  895. length += sizeof(Int64); //dataValue->serverTimestamp
  896. }
  897. if (p->encodingMask & 0x10) {
  898. length += sizeof(Int64); //dataValue->sourcePicoseconds
  899. }
  900. if (p->encodingMask & 0x20) {
  901. length += sizeof(Int64); //dataValue->serverPicoseconds
  902. }
  903. }
  904. return length;
  905. }
  906. /**
  907. * RequestHeader
  908. * Part: 4
  909. * Chapter: 7.26
  910. * Page: 132
  911. */
  912. /** \copydoc decodeRequestHeader */
  913. /*** Sten: removed to compile
  914. Int32 decodeRequestHeader(const AD_RawMessage *srcRaw, Int32 *pos,
  915. UA_AD_RequestHeader *dstRequestHeader) {
  916. return decoder_decodeRequestHeader(srcRaw->message, pos, dstRequestHeader);
  917. }
  918. ***/
  919. /*** Sten: removed to compile
  920. Int32 decoder_decodeRequestHeader(char const * message, Int32 *pos,
  921. UA_AD_RequestHeader *dstRequestHeader) {
  922. // 62541-4 §5.5.2.2 OpenSecureChannelServiceParameters
  923. // requestHeader - common request parameters. The authenticationToken is always omitted
  924. decoder_decodeBuiltInDatatype(message, NODE_ID, pos,
  925. &(dstRequestHeader->authenticationToken));
  926. decoder_decodeBuiltInDatatype(message, DATE_TIME, pos,
  927. &(dstRequestHeader->timestamp));
  928. decoder_decodeBuiltInDatatype(message, UINT32, pos,
  929. &(dstRequestHeader->requestHandle));
  930. decoder_decodeBuiltInDatatype(message, UINT32, pos,
  931. &(dstRequestHeader->returnDiagnostics));
  932. decoder_decodeBuiltInDatatype(message, STRING, pos,
  933. &(dstRequestHeader->auditEntryId));
  934. decoder_decodeBuiltInDatatype(message, UINT32, pos,
  935. &(dstRequestHeader->timeoutHint));
  936. decoder_decodeBuiltInDatatype(message, EXTENSION_OBJECT, pos,
  937. &(dstRequestHeader->additionalHeader));
  938. // AdditionalHeader will stay empty, need to be changed if there is relevant information
  939. return 0;
  940. }
  941. ***/
  942. /**
  943. * ResponseHeader
  944. * Part: 4
  945. * Chapter: 7.27
  946. * Page: 133
  947. */
  948. /** \copydoc encodeResponseHeader */
  949. /*** Sten: removed to compile
  950. Int32 encodeResponseHeader(UA_AD_ResponseHeader const * responseHeader,
  951. Int32 *pos, UA_ByteString *dstBuf) {
  952. encodeUADateTime(responseHeader->timestamp, pos, dstBuf->data);
  953. encodeIntegerId(responseHeader->requestHandle, pos, dstBuf->data);
  954. encodeUInt32(responseHeader->serviceResult, pos, dstBuf->data);
  955. encodeDiagnosticInfo(responseHeader->serviceDiagnostics, pos, dstBuf->data);
  956. encoder_encodeBuiltInDatatypeArray(responseHeader->stringTable,
  957. responseHeader->noOfStringTable, STRING_ARRAY, pos, dstBuf->data);
  958. encodeExtensionObject(responseHeader->additionalHeader, pos, dstBuf->data);
  959. //Kodieren von String Datentypen
  960. return 0;
  961. }
  962. ***/
  963. /*** Sten: removed to compile
  964. Int32 extensionObject_calcSize(UA_ExtensionObject *extensionObject) {
  965. Int32 length = 0;
  966. length += nodeId_calcSize(&(extensionObject->typeId));
  967. length += sizeof(Byte); //The EncodingMask Byte
  968. if (extensionObject->encoding == BODY_IS_BYTE_STRING
  969. || extensionObject->encoding == BODY_IS_XML_ELEMENT) {
  970. length += UAByteString_calcSize(&(extensionObject->body));
  971. }
  972. return length;
  973. }
  974. ***/
  975. /*** Sten: removed to compile
  976. Int32 responseHeader_calcSize(UA_AD_ResponseHeader *responseHeader) {
  977. Int32 i;
  978. Int32 length = 0;
  979. // UtcTime timestamp 8
  980. length += sizeof(UA_DateTime);
  981. // IntegerId requestHandle 4
  982. length += sizeof(UA_AD_IntegerId);
  983. // StatusCode serviceResult 4
  984. length += sizeof(UA_StatusCode);
  985. // DiagnosticInfo serviceDiagnostics
  986. length += diagnosticInfo_calcSize(responseHeader->serviceDiagnostics);
  987. // String stringTable[], see 62541-6 § 5.2.4
  988. length += sizeof(Int32); // Length of Stringtable always
  989. if (responseHeader->noOfStringTable > 0) {
  990. for (i = 0; i < responseHeader->noOfStringTable; i++) {
  991. length += UAString_calcSize(responseHeader->stringTable[i]);
  992. }
  993. }
  994. // ExtensibleObject additionalHeader
  995. length += extensionObject_calcSize(responseHeader->additionalHeader);
  996. return length;
  997. }
  998. ***/