opcua_basictypes.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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_Array_decode(char const * src, Int32 noElements, Int32 type, Int32* pos, void const **dst) {
  30. //TODO: Implement
  31. return UA_ERR_NOT_IMPLEMENTED;
  32. }
  33. Int32 UA_free(void * ptr){
  34. free(ptr);
  35. return UA_SUCCESS;
  36. }
  37. Int32 UA_alloc(void ** ptr, int size){
  38. *ptr = malloc(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 NIEVT_TWO_BYTE:
  356. length += 2 * sizeof(UA_Byte);
  357. break;
  358. case NIEVT_FOUR_BYTE:
  359. length += 4 * sizeof(UA_Byte);
  360. break;
  361. case NIEVT_NUMERIC:
  362. length += sizeof(UA_Byte) + sizeof(UA_UInt16) + sizeof(UInt32);
  363. break;
  364. case NIEVT_STRING:
  365. length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_String_calcSize(&(p->identifier.string));
  366. break;
  367. case NIEVT_GUID:
  368. length += sizeof(UA_Byte) + sizeof(UA_UInt16) + UA_Guid_calcSize(&(p->identifier.guid));
  369. break;
  370. case NIEVT_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 NIEVT_TWO_BYTE:
  387. srcByte = src->identifier.numeric;
  388. retval |= UA_Byte_encode(&srcByte,pos,dst);
  389. break;
  390. case NIEVT_FOUR_BYTE:
  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 NIEVT_NUMERIC:
  397. retval |= UA_UInt16_encode(&(src->namespace), pos, dst);
  398. retval |= UA_UInt32_encode(&(src->identifier.numeric), pos, dst);
  399. break;
  400. case NIEVT_STRING:
  401. retval |= UA_UInt16_encode(&(src->namespace), pos, dst);
  402. retval |= UA_String_encode(&(src->identifier.string), pos, dst);
  403. break;
  404. case NIEVT_GUID:
  405. retval |= UA_UInt16_encode(&(src->namespace), pos, dst);
  406. retval |= UA_Guid_encode(&(src->identifier.guid), pos, dst);
  407. break;
  408. case NIEVT_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 NIEVT_TWO_BYTE: // 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 NIEVT_FOUR_BYTE: // 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 NIEVT_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 NIEVT_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 NIEVT_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 NIEVT_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 NIEVT_TWO_BYTE:
  457. case NIEVT_FOUR_BYTE:
  458. case NIEVT_NUMERIC:
  459. // nothing to do
  460. break;
  461. case NIEVT_STRING: // Table 6, second entry
  462. retval |= UA_String_deleteMembers(&(p->identifier.string));
  463. break;
  464. case NIEVT_GUID: // Table 6, third entry
  465. retval |= UA_Guid_deleteMembers(&(p->identifier.guid));
  466. break;
  467. case NIEVT_BYTESTRING: // Table 6, "OPAQUE"
  468. retval |= UA_ByteString_deleteMembers(&(p->identifier.byteString));
  469. break;
  470. }
  471. return retval;
  472. }
  473. Int32 UA_ExpandedNodeId_calcSize(UA_ExpandedNodeId const * p) {
  474. Int32 length = 0;
  475. if (p == UA_NULL) {
  476. length = sizeof(UA_ExpandedNodeId);
  477. } else {
  478. length = UA_NodeId_calcSize(&(p->nodeId));
  479. if (p->nodeId.encodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  480. length += UA_String_calcSize(&(p->namespaceUri)); //p->namespaceUri
  481. }
  482. if (p->nodeId.encodingByte & NIEVT_SERVERINDEX_FLAG) {
  483. length += sizeof(UA_UInt32); //p->serverIndex
  484. }
  485. }
  486. return length;
  487. }
  488. Int32 UA_ExpandedNodeId_encode(UA_ExpandedNodeId const * src, Int32* pos, char *dst) {
  489. UInt32 retval = UA_SUCCESS;
  490. retval |= UA_NodeId_encode(&(src->nodeId),pos,dst);
  491. if (src->nodeId.encodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  492. retval |= UA_String_encode(&(src->namespaceUri),pos,dst);
  493. }
  494. if (src->nodeId.encodingByte & NIEVT_SERVERINDEX_FLAG) {
  495. retval |= UA_UInt32_encode(&(src->serverIndex),pos,dst);
  496. }
  497. return retval;
  498. }
  499. Int32 UA_ExpandedNodeId_decode(char const * src, Int32* pos,
  500. UA_ExpandedNodeId *dst) {
  501. UInt32 retval = UA_SUCCESS;
  502. retval |= UA_NodeId_decode(src,pos,&(dst->nodeId));
  503. if (dst->nodeId.encodingByte & NIEVT_NAMESPACE_URI_FLAG) {
  504. dst->nodeId.namespace = 0;
  505. retval |= UA_String_decode(src,pos,&(dst->namespaceUri));
  506. } else {
  507. retval |= UA_String_copy(&UA_String_null, &(dst->namespaceUri));
  508. }
  509. if (dst->nodeId.encodingByte & NIEVT_SERVERINDEX_FLAG) {
  510. retval |= UA_UInt32_decode(src,pos,&(dst->serverIndex));
  511. }
  512. return retval;
  513. }
  514. UA_TYPE_METHOD_DELETE_STRUCT(UA_ExpandedNodeId)
  515. Int32 UA_ExpandedNodeId_deleteMembers(UA_ExpandedNodeId* p) {
  516. Int32 retval = UA_SUCCESS;
  517. retval |= UA_NodeId_deleteMembers(&(p->nodeId));
  518. retval |= UA_String_deleteMembers(&(p->namespaceUri));
  519. return retval;
  520. }
  521. Int32 UA_ExtensionObject_calcSize(UA_ExtensionObject const * p) {
  522. Int32 length = 0;
  523. if (p == UA_NULL) {
  524. length = sizeof(UA_ExtensionObject);
  525. } else {
  526. length += UA_NodeId_calcSize(&(p->typeId));
  527. length += sizeof(Byte); //p->encoding
  528. switch (p->encoding) {
  529. case 0x00:
  530. length += sizeof(UA_Int32); //p->body.length
  531. break;
  532. case 0x01:
  533. length += UA_ByteString_calcSize(&(p->body));
  534. break;
  535. case 0x02:
  536. length += UA_ByteString_calcSize(&(p->body));
  537. break;
  538. }
  539. }
  540. return length;
  541. }
  542. Int32 UA_ExtensionObject_encode(UA_ExtensionObject const *src, Int32* pos, char * dst) {
  543. Int32 retval = UA_SUCCESS;
  544. retval |= UA_NodeId_encode(&(src->typeId),pos,dst);
  545. retval |= UA_Byte_encode(&(src->encoding),pos,dst);
  546. switch (src->encoding) {
  547. case NO_BODY_IS_ENCODED:
  548. break;
  549. case BODY_IS_BYTE_STRING:
  550. case BODY_IS_XML_ELEMENT:
  551. retval |= UA_ByteString_encode(&(src->body),pos,dst);
  552. break;
  553. }
  554. return retval;
  555. }
  556. Int32 UA_ExtensionObject_decode(char const * src, Int32 *pos,
  557. UA_ExtensionObject *dst) {
  558. Int32 retval = UA_SUCCESS;
  559. retval |= UA_NodeId_decode(src,pos,&(dst->typeId));
  560. retval |= UA_Byte_decode(src,pos,&(dst->encoding));
  561. retval |= UA_String_copy(&UA_String_null, (UA_String*) &(dst->body));
  562. switch (dst->encoding) {
  563. case NO_BODY_IS_ENCODED:
  564. break;
  565. case BODY_IS_BYTE_STRING:
  566. case BODY_IS_XML_ELEMENT:
  567. retval |= UA_ByteString_decode(src,pos,&(dst->body));
  568. break;
  569. }
  570. return retval;
  571. }
  572. UA_TYPE_METHOD_DELETE_STRUCT(UA_ExtensionObject)
  573. Int32 UA_ExtensionObject_deleteMembers(UA_ExtensionObject *p) {
  574. Int32 retval = UA_SUCCESS;
  575. retval |= UA_NodeId_deleteMembers(&(p->typeId));
  576. retval |= UA_ByteString_deleteMembers(&(p->body));
  577. return retval;
  578. }
  579. // TODO: UA_DataValue_encode
  580. // TODO: UA_DataValue_decode
  581. // TODO: UA_DataValue_delete
  582. // TODO: UA_DataValue_deleteMembers
  583. /** DiagnosticInfo - Part: 4, Chapter: 7.9, Page: 116 */
  584. Int32 UA_DiagnosticInfo_decode(char const * src, Int32 *pos, UA_DiagnosticInfo *dst) {
  585. Int32 retval = UA_SUCCESS;
  586. int i;
  587. retval |= UA_Byte_decode(src, pos, &(dst->encodingMask));
  588. for (i = 0; i < 7; i++) {
  589. switch ( (0x01 << i) & dst->encodingMask) {
  590. case DIEMT_SYMBOLIC_ID:
  591. retval |= UA_Int32_decode(src, pos, &(dst->symbolicId));
  592. break;
  593. case DIEMT_NAMESPACE:
  594. retval |= UA_Int32_decode(src, pos, &(dst->namespaceUri));
  595. break;
  596. case DIEMT_LOCALIZED_TEXT:
  597. retval |= UA_Int32_decode(src, pos, &(dst->localizedText));
  598. break;
  599. case DIEMT_LOCALE:
  600. retval |= UA_Int32_decode(src, pos, &(dst->locale));
  601. break;
  602. case DIEMT_ADDITIONAL_INFO:
  603. retval |= UA_String_decode(src, pos, &(dst->additionalInfo));
  604. break;
  605. case DIEMT_INNER_STATUS_CODE:
  606. retval |= UA_StatusCode_decode(src, pos, &(dst->innerStatusCode));
  607. break;
  608. case DIEMT_INNER_DIAGNOSTIC_INFO:
  609. // innerDiagnosticInfo is a pointer to struct, therefore allocate
  610. retval |= UA_alloc((void **) &(dst->innerDiagnosticInfo),UA_DiagnosticInfo_calcSize(UA_NULL));
  611. retval |= UA_DiagnosticInfo_decode(src, pos, dst->innerDiagnosticInfo);
  612. break;
  613. }
  614. }
  615. return retval;
  616. }
  617. Int32 UA_DiagnosticInfo_encode(UA_DiagnosticInfo const *src, Int32 *pos, char *dst) {
  618. Int32 retval = UA_SUCCESS;
  619. Byte mask;
  620. int i;
  621. UA_Byte_encode(&(src->encodingMask), pos, dst);
  622. for (i = 0; i < 7; i++) {
  623. switch ( (0x01 << i) & src->encodingMask) {
  624. case DIEMT_SYMBOLIC_ID:
  625. retval |= UA_Int32_encode(&(src->symbolicId), pos, dst);
  626. break;
  627. case DIEMT_NAMESPACE:
  628. retval |= UA_Int32_encode( &(src->namespaceUri), pos, dst);
  629. break;
  630. case DIEMT_LOCALIZED_TEXT:
  631. retval |= UA_Int32_encode(&(src->localizedText), pos, dst);
  632. break;
  633. case DIEMT_LOCALE:
  634. retval |= UA_Int32_encode(&(src->locale), pos, dst);
  635. break;
  636. case DIEMT_ADDITIONAL_INFO:
  637. retval |= UA_String_encode(&(src->additionalInfo), pos, dst);
  638. break;
  639. case DIEMT_INNER_STATUS_CODE:
  640. retval |= UA_StatusCode_encode(&(src->innerStatusCode), pos, dst);
  641. break;
  642. case DIEMT_INNER_DIAGNOSTIC_INFO:
  643. retval |= UA_DiagnosticInfo_encode(src->innerDiagnosticInfo, pos, dst);
  644. break;
  645. }
  646. }
  647. return retval;
  648. }
  649. Int32 UA_DiagnosticInfo_calcSize(UA_DiagnosticInfo const * ptr) {
  650. Int32 length = 0;
  651. if (ptr == UA_NULL) {
  652. length = sizeof(UA_DiagnosticInfo);
  653. } else {
  654. Byte mask;
  655. length += sizeof(Byte); // EncodingMask
  656. for (mask = 0x01; mask <= 0x40; mask *= 2) {
  657. switch (mask & (ptr->encodingMask)) {
  658. case DIEMT_SYMBOLIC_ID:
  659. // puts("diagnosticInfo symbolic id");
  660. length += sizeof(UA_Int32);
  661. break;
  662. case DIEMT_NAMESPACE:
  663. length += sizeof(UA_Int32);
  664. break;
  665. case DIEMT_LOCALIZED_TEXT:
  666. length += sizeof(UA_Int32);
  667. break;
  668. case DIEMT_LOCALE:
  669. length += sizeof(UA_Int32);
  670. break;
  671. case DIEMT_ADDITIONAL_INFO:
  672. length += UA_String_calcSize(&(ptr->additionalInfo));
  673. break;
  674. case DIEMT_INNER_STATUS_CODE:
  675. length += sizeof(UA_StatusCode);
  676. break;
  677. case DIEMT_INNER_DIAGNOSTIC_INFO:
  678. length += UA_DiagnosticInfo_calcSize(ptr->innerDiagnosticInfo);
  679. break;
  680. }
  681. }
  682. }
  683. return length;
  684. }
  685. UA_TYPE_METHOD_DELETE_STRUCT(UA_DiagnosticInfo)
  686. Int32 UA_DiagnosticInfo_deleteMembers(UA_DiagnosticInfo *p) {
  687. Int32 retval = UA_SUCCESS;
  688. if (p->encodingMask & DIEMT_INNER_DIAGNOSTIC_INFO) {
  689. retval |= UA_DiagnosticInfo_deleteMembers(p->innerDiagnosticInfo);
  690. retval |= UA_free(p->innerDiagnosticInfo);
  691. }
  692. return retval;
  693. }
  694. UA_TYPE_METHOD_CALCSIZE_SIZEOF(UA_DateTime)
  695. UA_TYPE_METHOD_ENCODE_AS(UA_DateTime,UA_Int64)
  696. UA_TYPE_METHOD_DECODE_AS(UA_DateTime,UA_Int64)
  697. UA_TYPE_METHOD_DELETE_FREE(UA_DateTime)
  698. UA_TYPE_METHOD_DELETEMEMBERS_NOACTION(UA_DateTime)
  699. UA_TYPE_METHOD_CALCSIZE_AS(UA_XmlElement, UA_ByteString)
  700. UA_TYPE_METHOD_ENCODE_AS(UA_XmlElement, UA_ByteString)
  701. UA_TYPE_METHOD_DECODE_AS(UA_XmlElement, UA_ByteString)
  702. UA_TYPE_METHOD_DELETE_AS(UA_XmlElement, UA_ByteString)
  703. UA_TYPE_METHOD_DELETEMEMBERS_AS(UA_XmlElement, UA_ByteString)
  704. /** IntegerId - Part: 4, Chapter: 7.13, Page: 118 */
  705. UA_TYPE_METHOD_CALCSIZE_AS(UA_IntegerId, UA_Int32)
  706. UA_TYPE_METHOD_ENCODE_AS(UA_IntegerId, UA_Int32)
  707. UA_TYPE_METHOD_DECODE_AS(UA_IntegerId, UA_Int32)
  708. UA_TYPE_METHOD_DELETE_AS(UA_IntegerId, UA_Int32)
  709. UA_TYPE_METHOD_DELETEMEMBERS_AS(UA_IntegerId, UA_Int32)
  710. UA_TYPE_METHOD_CALCSIZE_AS(UA_StatusCode, UA_UInt32)
  711. UA_TYPE_METHOD_ENCODE_AS(UA_StatusCode, UA_UInt32)
  712. UA_TYPE_METHOD_DECODE_AS(UA_StatusCode, UA_UInt32)
  713. UA_TYPE_METHOD_DELETE_AS(UA_StatusCode, UA_UInt32)
  714. UA_TYPE_METHOD_DELETEMEMBERS_AS(UA_StatusCode, UA_UInt32)
  715. Int32 UA_QualifiedName_calcSize(UA_QualifiedName const * p) {
  716. Int32 length = 0;
  717. length += sizeof(UInt16); //qualifiedName->namespaceIndex
  718. length += sizeof(UInt16); //qualifiedName->reserved
  719. length += UA_String_calcSize(&(p->name)); //qualifiedName->name
  720. return length;
  721. }
  722. Int32 UA_QualifiedName_decode(char const * src, Int32 *pos,
  723. UA_QualifiedName *dst) {
  724. Int32 retval = UA_SUCCESS;
  725. retval |= UA_UInt16_decode(src,pos,&(dst->namespaceIndex));
  726. retval |= UA_UInt16_decode(src,pos,&(dst->reserved));
  727. retval |= UA_String_decode(src,pos,&(dst->name));
  728. return retval;
  729. }
  730. Int32 UA_QualifiedName_encode(UA_QualifiedName const *src, Int32* pos,
  731. char *dst) {
  732. Int32 retval = UA_SUCCESS;
  733. retval |= UA_UInt16_encode(&(src->namespaceIndex),pos,dst);
  734. retval |= UA_UInt16_encode(&(src->reserved),pos,dst);
  735. retval |= UA_String_encode(&(src->name),pos,dst);
  736. return retval;
  737. }
  738. Int32 UA_Variant_calcSize(UA_Variant const * p) {
  739. Int32 length = 0;
  740. Int32 ns0Id = p->encodingMask & 0x1F; // Bits 1-5
  741. Boolean isArray = p->encodingMask & (0x01 << 7); // Bit 7
  742. Boolean hasDimensions = p->encodingMask & (0x01 << 6); // Bit 6
  743. int i;
  744. if (p->vt == UA_NULL || p->encodingMask != p->vt->Id) {
  745. return UA_ERR_INCONSISTENT;
  746. }
  747. length += sizeof(Byte); //p->encodingMask
  748. if (isArray) { // array length is encoded
  749. length += sizeof(Int32); //p->arrayLength
  750. if (p->arrayLength > 0) {
  751. // TODO: add suggestions of @jfpr to not iterate over arrays with fixed len elements
  752. for (i=0;i<p->arrayLength;i++) {
  753. length += p->vt->calcSize(p->data[i]);
  754. }
  755. }
  756. } else { //single value to encode
  757. length += p->vt->calcSize(p->data[0]);
  758. }
  759. if (hasDimensions) {
  760. //ToDo: tobeInsert: length += the calcSize for dimensions
  761. }
  762. return length;
  763. }
  764. Int32 UA_Variant_encode(UA_Variant const *src, Int32* pos, char *dst) {
  765. Int32 retval = UA_SUCCESS;
  766. int i;
  767. if (src->vt == UA_NULL || src->encodingMask != src->vt->Id) {
  768. return UA_ERR_INCONSISTENT;
  769. }
  770. retval |= UA_Byte_encode(&(src->encodingMask),pos,dst);
  771. if (src->encodingMask & (0x01 << 7)) { // encode array length
  772. retval |= UA_Int32_encode(&(src->arrayLength),pos,dst);
  773. }
  774. if (src->arrayLength > 0) {
  775. //encode array as given by variant type
  776. for (i=0;i<src->arrayLength;i++) {
  777. retval |= src->vt->encode(src->data[i],pos,dst);
  778. }
  779. } else {
  780. retval |= src->vt->encode(src->data[i],pos,dst);
  781. }
  782. if (src->encodingMask & (1 << 6)) { // encode array dimension field
  783. // TODO: encode array dimension field
  784. }
  785. return retval;
  786. }
  787. //FIXME:
  788. Int32 UA_Variant_decode(char const * src, Int32 *pos, UA_Variant *dst) {
  789. return UA_SUCCESS;
  790. //FIXME:
  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_namespace_zero[UA_namespace_zero_to_index(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. ***/