1#ifndef NDNPH_STORE_KV_HPP
2#define NDNPH_STORE_KV_HPP
4#include "../port/fs/port.hpp"
5#include "../tlv/value.hpp"
23 template<
typename... Arg>
25 if (m_fs ==
nullptr) {
29 return m_fs->
open(std::forward<Arg>(arg)...);
39 if (m_fs ==
nullptr || !checkKey(key)) {
42 int size = m_fs->
read(key,
nullptr, 0);
47 uint8_t* buf = region.
alloc(size);
51 int size2 = m_fs->
read(key, buf, size);
53 region.
free(buf, size);
70 if (m_fs ==
nullptr || !checkKey(key)) {
81 bool del(
const char* key) {
82 if (m_fs ==
nullptr || !checkKey(key)) {
81 bool del(
const char* key) {
…}
89 static bool checkKey(
const char* key) {
91 if (key ==
nullptr || (keyLen = strlen(key)) == 0) {
94 for (
size_t i = 0; i < keyLen; ++i) {
96 if (!isdigit(ch) && !islower(ch) && ch !=
'_') {
104 std::unique_ptr<port::FileStore> m_ownFs;
105 port::FileStore* m_fs =
nullptr;
File storage on microcontroller filesystem.
Definition fs.hpp:11
int read(const char *filename, uint8_t *buffer, size_t count)
bool unlink(const char *filename)
bool open(const char *path)
bool write(const char *filename, const uint8_t *buffer, size_t count)
File based key-value store.
Definition kv.hpp:10
bool del(const char *key)
Delete a key.
Definition kv.hpp:81
KvStore(port::FileStore &fs)
Constructor to use existing FileStore instance.
Definition kv.hpp:16
tlv::Value get(const char *key, Region ®ion)
Retrieve a value.
Definition kv.hpp:38
bool open(Arg &&... arg)
Open the FileStore backend.
Definition kv.hpp:24
bool set(const char *key, tlv::Value value)
Store a value.
Definition kv.hpp:69
KvStore()=default
Constructor to use internal FileStore instance.
Region-based memory allocator thats owns memory of NDNph objects.
Definition region.hpp:9
uint8_t * alloc(size_t size)
Allocate a buffer with no alignment requirement.
Definition region.hpp:27
bool free(const uint8_t *first, const uint8_t *last)
Deallocate (part of) last allocated buffer.
Definition region.hpp:51
A sequence of bytes, usually TLV-VALUE.
Definition value.hpp:11
const uint8_t * begin() const
Definition value.hpp:38
size_t size() const
Definition value.hpp:46