mf_classic_dict.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <storage/storage.h>
  4. #include <lib/flipper_format/flipper_format.h>
  5. #include <lib/toolbox/stream/file_stream.h>
  6. #include <lib/toolbox/stream/buffered_file_stream.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. typedef enum {
  11. MfClassicDictTypeUser,
  12. MfClassicDictTypeSystem,
  13. MfClassicDictTypeUnitTest,
  14. } MfClassicDictType;
  15. typedef struct MfClassicDict MfClassicDict;
  16. bool mf_classic_dict_check_presence(MfClassicDictType dict_type);
  17. /** Allocate MfClassicDict instance
  18. *
  19. * @param[in] dict_type The dictionary type
  20. *
  21. * @return MfClassicDict instance
  22. */
  23. MfClassicDict* mf_classic_dict_alloc(MfClassicDictType dict_type);
  24. /** Free MfClassicDict instance
  25. *
  26. * @param dict MfClassicDict instance
  27. */
  28. void mf_classic_dict_free(MfClassicDict* dict);
  29. /** Get total keys count
  30. *
  31. * @param dict MfClassicDict instance
  32. *
  33. * @return total keys count
  34. */
  35. uint32_t mf_classic_dict_get_total_keys(MfClassicDict* dict);
  36. /** Rewind to the beginning
  37. *
  38. * @param dict MfClassicDict instance
  39. *
  40. * @return true on success
  41. */
  42. bool mf_classic_dict_rewind(MfClassicDict* dict);
  43. bool mf_classic_dict_is_key_present(MfClassicDict* dict, uint8_t* key);
  44. bool mf_classic_dict_is_key_present_str(MfClassicDict* dict, FuriString* key);
  45. bool mf_classic_dict_get_next_key(MfClassicDict* dict, uint64_t* key);
  46. bool mf_classic_dict_get_next_key_str(MfClassicDict* dict, FuriString* key);
  47. /** Get key at target offset as uint64_t
  48. *
  49. * @param dict MfClassicDict instance
  50. * @param[out] key Pointer to the uint64_t key
  51. * @param[in] target Target offset from current position
  52. *
  53. * @return true on success
  54. */
  55. bool mf_classic_dict_get_key_at_index(MfClassicDict* dict, uint64_t* key, uint32_t target);
  56. /** Get key at target offset as FuriString*
  57. *
  58. * @param dict MfClassicDict instance
  59. * @param[out] key Found key destination buffer
  60. * @param[in] target Target offset from current position
  61. *
  62. * @return true on success
  63. */
  64. bool mf_classic_dict_get_key_at_index_str(MfClassicDict* dict, FuriString* key, uint32_t target);
  65. bool mf_classic_dict_add_key(MfClassicDict* dict, uint8_t* key);
  66. /** Add string representation of the key
  67. *
  68. * @param dict MfClassicDict instance
  69. * @param[in] key String representation of the key
  70. *
  71. * @return true on success
  72. */
  73. bool mf_classic_dict_add_key_str(MfClassicDict* dict, FuriString* key);
  74. bool mf_classic_dict_find_index(MfClassicDict* dict, uint8_t* key, uint32_t* target);
  75. bool mf_classic_dict_find_index_str(MfClassicDict* dict, FuriString* key, uint32_t* target);
  76. /** Delete key at target offset
  77. *
  78. * @param dict MfClassicDict instance
  79. * @param[in] target Target offset from current position
  80. *
  81. * @return true on success
  82. */
  83. bool mf_classic_dict_delete_index(MfClassicDict* dict, uint32_t target);
  84. #ifdef __cplusplus
  85. }
  86. #endif