ua_transport.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_UInt32 UA_MessageType_calcSizeBinary(UA_MessageType const *ptr) {
  8. return 3 * sizeof(UA_Byte);
  9. }
  10. UA_StatusCode UA_MessageType_encodeBinary(UA_MessageType const *src, UA_ByteString *dst, UA_UInt32 *offset) {
  11. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  12. UA_Byte tmpBuf[3];
  13. tmpBuf[0] = (UA_Byte)((((UA_Int32)*src) >> 16) );
  14. tmpBuf[1] = (UA_Byte)((((UA_Int32)*src) >> 8));
  15. tmpBuf[2] = (UA_Byte)(((UA_Int32)*src));
  16. retval |= UA_Byte_encodeBinary(&(tmpBuf[0]), dst, offset);
  17. retval |= UA_Byte_encodeBinary(&(tmpBuf[1]), dst, offset);
  18. retval |= UA_Byte_encodeBinary(&(tmpBuf[2]), dst, offset);
  19. return retval;
  20. }
  21. UA_StatusCode UA_MessageType_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset, UA_MessageType *dst) {
  22. if(*offset+3 > (UA_UInt32)src->length)
  23. return UA_STATUSCODE_BADDECODINGERROR;
  24. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  25. UA_Byte tmpBuf[3];
  26. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[0])); //messageType to Byte representation
  27. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[1]));
  28. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[2]));
  29. *dst = (UA_MessageType)((UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]));
  30. return retval;
  31. }
  32. #ifdef DEBUG
  33. void UA_MessageType_print(const UA_MessageType *p, FILE *stream) {
  34. UA_Byte *b = (UA_Byte *)p;
  35. fprintf(stream, "%c%c%c", b[2], b[1], b[0]);
  36. }
  37. #endif