cond_field_serialization.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #include <stdint.h>
  13. typedef uint32_t (*field_encoder_handler_t)(void const * const p_field,
  14. uint8_t * const p_buf,
  15. uint32_t buf_len,
  16. uint32_t * const p_index);
  17. typedef uint32_t (*field_decoder_handler_t)(uint8_t const * const p_buf,
  18. uint32_t buf_len,
  19. uint32_t * const p_index,
  20. void * p_field);
  21. /**@brief Function for safe encoding conditional field.
  22. *
  23. * Function sets 'presence flag' and checks if conditional field is provided and if it is not NULL
  24. * it calls provided parser function which attempts to encode field content to the buffer stream.
  25. *
  26. * @param[in] p_field Pointer to input struct.
  27. * @param[in] p_buf Pointer to the beginning of the output buffer.
  28. * @param[in] buf_len Size of buffer.
  29. * @param[in,out] p_index \c in: Index to start of uint8 value in buffer.
  30. * \c out: Index in buffer to first byte after the encoded data.
  31. * @param[in] fp_field_encoder Pointer to the function which implements fields encoding.
  32. *
  33. * @return NRF_SUCCESS Fields decoded successfully.
  34. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  35. */
  36. uint32_t cond_field_enc(void const * const p_field,
  37. uint8_t * const p_buf,
  38. uint32_t buf_len,
  39. uint32_t * const p_index,
  40. field_encoder_handler_t field_parser);
  41. /**@brief Function for safe decoding conditional field.
  42. *
  43. * Function checks if conditional field is present in the input buffer and if it is set it calls
  44. * provided parser function which attempts to parse buffer content to the known field.
  45. *
  46. * @param[in] p_buf Pointer to the beginning of the input buffer.
  47. * @param[in] buf_len Size of buffer.
  48. * @param[in,out] p_index \c in: Index to start of uint8 value in buffer.
  49. * \c out: Index in buffer to first byte after the decoded data.
  50. * @param[in] pp_field Pointer to pointer to output location.
  51. * @param[in] fp_field_decoder Pointer to the function which implements field decoding.
  52. *
  53. * @return NRF_SUCCESS Fields decoded successfully.
  54. * @retval NRF_ERROR_INVALID_LENGTH Decoding failure. Incorrect buffer length.
  55. */
  56. uint32_t cond_field_dec(uint8_t const * const p_buf,
  57. uint32_t buf_len,
  58. uint32_t * const p_index,
  59. void * * const pp_field,
  60. field_decoder_handler_t field_parser);