flipper_format_stream.h 2.0 KB

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