ua_types_encoding_binary.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #include "ua_types.h"
  17. typedef UA_StatusCode (*UA_exchangeEncodeBuffer)(void *handle, UA_Byte **bufPos,
  18. const UA_Byte **bufEnd);
  19. /* Encodes the scalar value described by type in the binary encoding. Encoding
  20. * is thread-safe if thread-local variables are enabled. Encoding is also
  21. * reentrant and can be safely called from signal handlers or interrupts.
  22. *
  23. * @param src The value. Must not be NULL.
  24. * @param type The value type. Must not be NULL.
  25. * @param bufPos Points to a pointer to the current position in the encoding
  26. * buffer. Must not be NULL. The pointer is advanced by the number of
  27. * encoded bytes, or, if the buffer is exchanged, to the position in the
  28. * new buffer.
  29. * @param bufEnd Points to a pointer to the end of the encoding buffer (encoding
  30. * always stops before *buf_end). Must not be NULL. The pointer is
  31. * changed when the buffer is exchanged.
  32. * @param exchangeCallback Called when the end of the buffer is reached. This is
  33. used to send out a message chunk before continuing with the encoding.
  34. Is ignored if NULL.
  35. * @param exchangeHandle Custom data passed into the exchangeCallback.
  36. * @return Returns a statuscode whether encoding succeeded. */
  37. UA_StatusCode
  38. UA_encodeBinary(const void *src, const UA_DataType *type,
  39. UA_Byte **bufPos, const UA_Byte **bufEnd,
  40. UA_exchangeEncodeBuffer exchangeCallback,
  41. void *exchangeHandle) UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  42. /* Decodes a scalar value described by type from binary encoding. Decoding
  43. * is thread-safe if thread-local variables are enabled. Decoding is also
  44. * reentrant and can be safely called from signal handlers or interrupts.
  45. *
  46. * @param src The buffer with the binary encoded value. Must not be NULL.
  47. * @param offset The current position in the buffer. Must not be NULL. The value
  48. * is advanced as decoding progresses.
  49. * @param dst The target value. Must not be NULL. The target is assumed to have
  50. * size type->memSize. The value is reset to zero before decoding. If
  51. * decoding fails, members are deleted and the value is reset (zeroed)
  52. * again.
  53. * @param type The value type. Must not be NULL.
  54. * @param customTypesSize The number of non-standard datatypes contained in the
  55. * customTypes array.
  56. * @param customTypes An array of non-standard datatypes (not included in
  57. * UA_TYPES). Can be NULL if customTypesSize is zero.
  58. * @return Returns a statuscode whether decoding succeeded. */
  59. UA_StatusCode
  60. UA_decodeBinary(const UA_ByteString *src, size_t *offset, void *dst,
  61. const UA_DataType *type, size_t customTypesSize,
  62. const UA_DataType *customTypes) UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  63. /* Returns the number of bytes the value p takes in binary encoding. Returns
  64. * zero if an error occurs. UA_calcSizeBinary is thread-safe and reentrant since
  65. * it does not access global (thread-local) variables. */
  66. size_t
  67. UA_calcSizeBinary(const void *p, const UA_DataType *type);
  68. const UA_DataType *
  69. UA_findDataTypeByBinary(const UA_NodeId *typeId);
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif /* UA_TYPES_ENCODING_BINARY_H_ */