opcua_basictypes.c 33 KB

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