ua_transport.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. if(*offset+3 > (UA_UInt32)src->length)
  24. return UA_ERROR;
  25. UA_Int32 retval = UA_SUCCESS;
  26. UA_Byte tmpBuf[3];
  27. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[0])); //messageType to Byte representation
  28. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[1]));
  29. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[2]));
  30. *dst = (UA_MessageType)((UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]));
  31. return retval;
  32. }
  33. #ifdef DEBUG
  34. void UA_MessageType_printf(char *label, UA_MessageType *p) {
  35. UA_Byte *b = (UA_Byte *)p;
  36. printf("%s{%c%c%c}\n", label, b[2], b[1], b[0]);
  37. }
  38. #endif