protocol_examples_utils.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Utility functions for protocol examples
  3. *
  4. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  5. *
  6. * SPDX-License-Identifier: Unlicense OR CC0-1.0
  7. */
  8. #pragma once
  9. #include <stdint.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief Encode an URI
  15. *
  16. * @param dest a destination memory location
  17. * @param src the source string
  18. * @param len the length of the source string
  19. * @return uint32_t the count of escaped characters
  20. *
  21. * @note Please allocate the destination buffer keeping in mind that encoding a
  22. * special character will take up 3 bytes (for '%' and two hex digits).
  23. * In the worst-case scenario, the destination buffer will have to be 3 times
  24. * that of the source string.
  25. */
  26. uint32_t example_uri_encode(char *dest, const char *src, size_t len);
  27. /**
  28. * @brief Decode an URI
  29. *
  30. * @param dest a destination memory location
  31. * @param src the source string
  32. * @param len the length of the source string
  33. *
  34. * @note Please allocate the destination buffer keeping in mind that a decoded
  35. * special character will take up 2 less bytes than its encoded form.
  36. * In the worst-case scenario, the destination buffer will have to be
  37. * the same size that of the source string.
  38. */
  39. void example_uri_decode(char *dest, const char *src, size_t len);
  40. #ifdef __cplusplus
  41. }
  42. #endif