opcua_basictypes.c 33 KB

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