luat_fskv.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef LUAT_FSKV_H
  22. #define LUAT_FSKV_H
  23. #include "lfs.h"
  24. /**
  25. * @defgroup luatos_fskv 持久化数据存储接口
  26. * @{
  27. */
  28. /**
  29. * @brief 初始化kv数据存储
  30. *
  31. * @return int == 0 正常 != 0失败
  32. */
  33. int luat_fskv_init(void);
  34. /**
  35. * @brief 删除指定的key
  36. * @param key[IN] 待删除的key值
  37. * @return int == 0 正常 != 0失败
  38. */
  39. int luat_fskv_del(const char* key);
  40. /**
  41. * @brief 写入指定key的数据
  42. * @param key[IN] 待写入的key值,不能为NULL,必须是\0结尾,最大长度64字节
  43. * @param data[IN] 待写入的数据, 不需要\0结尾
  44. * @param len[IN] 待写入的数据长度, 不含\0,当前支持最大长度255字节
  45. * @return int == 0 正常 != 0失败
  46. */
  47. int luat_fskv_set(const char* key, void* data, size_t len);
  48. int luat_fskv_size(const char* key, char buff[4]);
  49. /**
  50. * @brief 读取指定key的数据
  51. * @param key[IN] 待读取的key值,不能为NULL,必须是\0结尾
  52. * @param data[IN] 待读取的数据, 可写入空间必须大于等于len值
  53. * @param len[IN] 待读取的数据长度最大长度, 不含\0
  54. * @return int > 0 实际读取的长度, <=0 失败
  55. */
  56. int luat_fskv_get(const char* key, void* data, size_t len);
  57. /**
  58. * @brief 清空所有数据
  59. * @return int == 0 正常 != 0失败
  60. */
  61. int luat_fskv_clear(void);
  62. int luat_fskv_stat(size_t *using_sz, size_t *max_sz, size_t *kv_count);
  63. int luat_fskv_next(char* buff, size_t offset);
  64. /**
  65. * @}
  66. */
  67. #endif