flipper_format_stream.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <toolbox/stream/stream.h>
  5. #include <mlib/m-string.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. typedef enum {
  10. FlipperStreamValueIgnore,
  11. FlipperStreamValueStr,
  12. FlipperStreamValueHex,
  13. FlipperStreamValueFloat,
  14. FlipperStreamValueInt32,
  15. FlipperStreamValueUint32,
  16. } FlipperStreamValue;
  17. typedef struct {
  18. const char* key;
  19. FlipperStreamValue type;
  20. const void* data;
  21. size_t data_size;
  22. } FlipperStreamWriteData;
  23. /**
  24. * Writes a key/value pair to the stream.
  25. * @param stream
  26. * @param write_data
  27. * @return true
  28. * @return false
  29. */
  30. bool flipper_format_stream_write_value_line(Stream* stream, FlipperStreamWriteData* write_data);
  31. /**
  32. * Reads a value by key from a stream.
  33. * @param stream
  34. * @param key
  35. * @param type
  36. * @param _data
  37. * @param data_size
  38. * @param strict_mode
  39. * @return true
  40. * @return false
  41. */
  42. bool flipper_format_stream_read_value_line(
  43. Stream* stream,
  44. const char* key,
  45. FlipperStreamValue type,
  46. void* _data,
  47. size_t data_size,
  48. bool strict_mode);
  49. /**
  50. * Get the count of values by key from a stream.
  51. * @param stream
  52. * @param key
  53. * @param count
  54. * @param strict_mode
  55. * @return true
  56. * @return false
  57. */
  58. bool flipper_format_stream_get_value_count(
  59. Stream* stream,
  60. const char* key,
  61. uint32_t* count,
  62. bool strict_mode);
  63. /**
  64. * Removes a key and the corresponding value string from the stream and inserts a new key/value pair.
  65. * @param stream
  66. * @param write_data
  67. * @param strict_mode
  68. * @return true
  69. * @return false
  70. */
  71. bool flipper_format_stream_delete_key_and_write(
  72. Stream* stream,
  73. FlipperStreamWriteData* write_data,
  74. bool strict_mode);
  75. /**
  76. * Writes a comment string to the stream.
  77. * @param stream
  78. * @param data
  79. * @return true
  80. * @return false
  81. */
  82. bool flipper_format_stream_write_comment_cstr(Stream* stream, const char* data);
  83. #ifdef __cplusplus
  84. }
  85. #endif