ua_transport.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifdef DEBUG
  2. #include <stdio.h>
  3. #endif
  4. #include "ua_transport.h"
  5. #include "ua_util.h"
  6. UA_TYPE_DEFAULT(UA_MessageType)
  7. UA_Int32 UA_MessageType_calcSizeBinary(UA_MessageType const *ptr) {
  8. if(ptr == UA_NULL) return sizeof(UA_MessageType);
  9. return 3 * sizeof(UA_Byte);
  10. }
  11. UA_Int32 UA_MessageType_encodeBinary(UA_MessageType const *src, UA_ByteString *dst, UA_UInt32 *offset) {
  12. UA_Int32 retval = UA_SUCCESS;
  13. UA_Byte tmpBuf[3];
  14. tmpBuf[0] = (UA_Byte)((((UA_Int32)*src) >> 16) );
  15. tmpBuf[1] = (UA_Byte)((((UA_Int32)*src) >> 8));
  16. tmpBuf[2] = (UA_Byte)(((UA_Int32)*src));
  17. retval |= UA_Byte_encodeBinary(&(tmpBuf[0]), dst, offset);
  18. retval |= UA_Byte_encodeBinary(&(tmpBuf[1]), dst, offset);
  19. retval |= UA_Byte_encodeBinary(&(tmpBuf[2]), dst, offset);
  20. return retval;
  21. }
  22. UA_Int32 UA_MessageType_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset, UA_MessageType *dst) {
  23. UA_Int32 retval = UA_SUCCESS;
  24. UA_Byte tmpBuf[3];
  25. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[0])); //messageType to Byte representation
  26. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[1]));
  27. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[2]));
  28. *dst = (UA_MessageType)((UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]));
  29. return retval;
  30. }
  31. #ifdef DEBUG
  32. void UA_MessageType_printf(char *label, UA_MessageType *p) {
  33. UA_Byte *b = (UA_Byte *)p;
  34. printf("%s{%c%c%c}\n", label, b[2], b[1], b[0]);
  35. }
  36. #endif