ua_transport.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifdef UA_DEBUG
  2. #include <stdio.h>
  3. #endif
  4. #include "ua_connection.h"
  5. #include "ua_transport.h"
  6. #include "ua_types_macros.h"
  7. #include "ua_util.h"
  8. // max message size is 64k
  9. const UA_ConnectionConfig UA_ConnectionConfig_standard =
  10. {.protocolVersion = 0, .sendBufferSize = 65536, .recvBufferSize = 65536,
  11. .maxMessageSize = 65536, .maxChunkCount = 1};
  12. UA_TYPE_DEFAULT(UA_MessageType)
  13. UA_UInt32 UA_MessageType_calcSizeBinary(UA_MessageType const *ptr) {
  14. return 3 * sizeof(UA_Byte);
  15. }
  16. UA_StatusCode UA_MessageType_encodeBinary(UA_MessageType const *src, UA_ByteString *dst, UA_UInt32 *offset) {
  17. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  18. UA_Byte tmpBuf[3];
  19. tmpBuf[0] = (UA_Byte)(((UA_Int32)*src) >> 16);
  20. tmpBuf[1] = (UA_Byte)(((UA_Int32)*src) >> 8);
  21. tmpBuf[2] = (UA_Byte)((UA_Int32)*src);
  22. retval |= UA_Byte_encodeBinary(&(tmpBuf[0]), dst, offset);
  23. retval |= UA_Byte_encodeBinary(&(tmpBuf[1]), dst, offset);
  24. retval |= UA_Byte_encodeBinary(&(tmpBuf[2]), dst, offset);
  25. return retval;
  26. }
  27. UA_StatusCode UA_MessageType_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset, UA_MessageType *dst) {
  28. if(*offset+3 > (UA_UInt32)src->length)
  29. return UA_STATUSCODE_BADDECODINGERROR;
  30. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  31. UA_Byte tmpBuf[3];
  32. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[0])); //messageType to Byte representation
  33. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[1]));
  34. retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[2]));
  35. *dst = (UA_MessageType)((UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]));
  36. return retval;
  37. }
  38. #ifdef UA_DEBUG
  39. void UA_MessageType_print(const UA_MessageType *p, FILE *stream) {
  40. const UA_Byte *b = (const UA_Byte *)p;
  41. fprintf(stream, "%c%c%c", b[2], b[1], b[0]);
  42. }
  43. #endif