flipper_format_stream.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. FlipperStreamValueBool,
  17. } FlipperStreamValue;
  18. typedef struct {
  19. const char* key;
  20. FlipperStreamValue type;
  21. const void* data;
  22. size_t data_size;
  23. } FlipperStreamWriteData;
  24. /**
  25. * Writes a key/value pair to the stream.
  26. * @param stream
  27. * @param write_data
  28. * @return true
  29. * @return false
  30. */
  31. bool flipper_format_stream_write_value_line(Stream* stream, FlipperStreamWriteData* write_data);
  32. /**
  33. * Reads a value by key from a stream.
  34. * @param stream
  35. * @param key
  36. * @param type
  37. * @param _data
  38. * @param data_size
  39. * @param strict_mode
  40. * @return true
  41. * @return false
  42. */
  43. bool flipper_format_stream_read_value_line(
  44. Stream* stream,
  45. const char* key,
  46. FlipperStreamValue type,
  47. void* _data,
  48. size_t data_size,
  49. bool strict_mode);
  50. /**
  51. * Get the count of values by key from a stream.
  52. * @param stream
  53. * @param key
  54. * @param count
  55. * @param strict_mode
  56. * @return true
  57. * @return false
  58. */
  59. bool flipper_format_stream_get_value_count(
  60. Stream* stream,
  61. const char* key,
  62. uint32_t* count,
  63. bool strict_mode);
  64. /**
  65. * Removes a key and the corresponding value string from the stream and inserts a new key/value pair.
  66. * @param stream
  67. * @param write_data
  68. * @param strict_mode
  69. * @return true
  70. * @return false
  71. */
  72. bool flipper_format_stream_delete_key_and_write(
  73. Stream* stream,
  74. FlipperStreamWriteData* write_data,
  75. bool strict_mode);
  76. /**
  77. * Writes a comment string to the stream.
  78. * @param stream
  79. * @param data
  80. * @return true
  81. * @return false
  82. */
  83. bool flipper_format_stream_write_comment_cstr(Stream* stream, const char* data);
  84. #ifdef __cplusplus
  85. }
  86. #endif