ua_types_encoding_binary.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright 2014-2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. * Copyright 2015 (c) Sten Grüner
  7. * Copyright 2014, 2017 (c) Florian Palm
  8. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  9. * Copyright 2017 (c) Mark Giraud, Fraunhofer IOSB
  10. */
  11. #ifndef UA_TYPES_ENCODING_BINARY_H_
  12. #define UA_TYPES_ENCODING_BINARY_H_
  13. #include "ua_types.h"
  14. _UA_BEGIN_DECLS
  15. typedef UA_StatusCode (*UA_exchangeEncodeBuffer)(void *handle, UA_Byte **bufPos,
  16. const UA_Byte **bufEnd);
  17. /* Encodes the scalar value described by type in the binary encoding. Encoding
  18. * is thread-safe if thread-local variables are enabled. Encoding is also
  19. * reentrant and can be safely called from signal handlers or interrupts.
  20. *
  21. * @param src The value. Must not be NULL.
  22. * @param type The value type. Must not be NULL.
  23. * @param bufPos Points to a pointer to the current position in the encoding
  24. * buffer. Must not be NULL. The pointer is advanced by the number of
  25. * encoded bytes, or, if the buffer is exchanged, to the position in the
  26. * new buffer.
  27. * @param bufEnd Points to a pointer to the end of the encoding buffer (encoding
  28. * always stops before *buf_end). Must not be NULL. The pointer is
  29. * changed when the buffer is exchanged.
  30. * @param exchangeCallback Called when the end of the buffer is reached. This is
  31. used to send out a message chunk before continuing with the encoding.
  32. Is ignored if NULL.
  33. * @param exchangeHandle Custom data passed into the exchangeCallback.
  34. * @return Returns a statuscode whether encoding succeeded. */
  35. //TODO remove UA_EXPORT after we fix issue #1914
  36. UA_StatusCode UA_EXPORT
  37. UA_encodeBinary(const void *src, const UA_DataType *type,
  38. UA_Byte **bufPos, const UA_Byte **bufEnd,
  39. UA_exchangeEncodeBuffer exchangeCallback,
  40. void *exchangeHandle) UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  41. /* Decodes a scalar value described by type from binary encoding. Decoding
  42. * is thread-safe if thread-local variables are enabled. Decoding is also
  43. * reentrant and can be safely called from signal handlers or interrupts.
  44. *
  45. * @param src The buffer with the binary encoded value. Must not be NULL.
  46. * @param offset The current position in the buffer. Must not be NULL. The value
  47. * is advanced as decoding progresses.
  48. * @param dst The target value. Must not be NULL. The target is assumed to have
  49. * size type->memSize. The value is reset to zero before decoding. If
  50. * decoding fails, members are deleted and the value is reset (zeroed)
  51. * again.
  52. * @param type The value type. Must not be NULL.
  53. * @param customTypesSize The number of non-standard datatypes contained in the
  54. * customTypes array.
  55. * @param customTypes An array of non-standard datatypes (not included in
  56. * UA_TYPES). Can be NULL if customTypesSize is zero.
  57. * @return Returns a statuscode whether decoding succeeded. */
  58. UA_StatusCode
  59. UA_decodeBinary(const UA_ByteString *src, size_t *offset, void *dst,
  60. const UA_DataType *type, const UA_DataTypeArray *customTypes)
  61. UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  62. /* Returns the number of bytes the value p takes in binary encoding. Returns
  63. * zero if an error occurs. UA_calcSizeBinary is thread-safe and reentrant since
  64. * it does not access global (thread-local) variables. */
  65. size_t
  66. UA_calcSizeBinary(const void *p, const UA_DataType *type);
  67. const UA_DataType *
  68. UA_findDataTypeByBinary(const UA_NodeId *typeId);
  69. _UA_END_DECLS
  70. #endif /* UA_TYPES_ENCODING_BINARY_H_ */