ua_types_encoding_binary.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <open62541/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. UA_StatusCode
  36. UA_encodeBinary(const void *src, const UA_DataType *type,
  37. UA_Byte **bufPos, const UA_Byte **bufEnd,
  38. UA_exchangeEncodeBuffer exchangeCallback,
  39. void *exchangeHandle) UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  40. /* Decodes a scalar value described by type from binary encoding. Decoding
  41. * is thread-safe if thread-local variables are enabled. Decoding is also
  42. * reentrant and can be safely called from signal handlers or interrupts.
  43. *
  44. * @param src The buffer with the binary encoded value. Must not be NULL.
  45. * @param offset The current position in the buffer. Must not be NULL. The value
  46. * is advanced as decoding progresses.
  47. * @param dst The target value. Must not be NULL. The target is assumed to have
  48. * size type->memSize. The value is reset to zero before decoding. If
  49. * decoding fails, members are deleted and the value is reset (zeroed)
  50. * again.
  51. * @param type The value type. Must not be NULL.
  52. * @param customTypesSize The number of non-standard datatypes contained in the
  53. * customTypes array.
  54. * @param customTypes An array of non-standard datatypes (not included in
  55. * UA_TYPES). Can be NULL if customTypesSize is zero.
  56. * @return Returns a statuscode whether decoding succeeded. */
  57. UA_StatusCode
  58. UA_decodeBinary(const UA_ByteString *src, size_t *offset, void *dst,
  59. const UA_DataType *type, const UA_DataTypeArray *customTypes)
  60. UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  61. /* Returns the number of bytes the value p takes in binary encoding. Returns
  62. * zero if an error occurs. UA_calcSizeBinary is thread-safe and reentrant since
  63. * it does not access global (thread-local) variables. */
  64. size_t
  65. UA_calcSizeBinary(const void *p, const UA_DataType *type);
  66. const UA_DataType *
  67. UA_findDataTypeByBinary(const UA_NodeId *typeId);
  68. _UA_END_DECLS
  69. #endif /* UA_TYPES_ENCODING_BINARY_H_ */