opcua_basictypes.c 33 KB

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