2023-10-06 03:13:46 +00:00
|
|
|
#ifndef KLIB_PHONEBOOK_H
|
|
|
|
#define KLIB_PHONEBOOK_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arena.h"
|
|
|
|
#include "TLV.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define PHONEBOOK_KEY_TAG 1
|
|
|
|
#define PHONEBOOK_VAL_TAG 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Phonebook {
|
|
|
|
public:
|
|
|
|
Phonebook(Arena &arena) :
|
2023-10-06 06:08:35 +00:00
|
|
|
arena(arena),
|
|
|
|
kTag(PHONEBOOK_KEY_TAG),
|
|
|
|
vTag(PHONEBOOK_VAL_TAG) {} ;
|
2023-10-06 03:13:46 +00:00
|
|
|
Phonebook(Arena &arena, uint8_t kt, uint8_t vt) :
|
2023-10-06 06:08:35 +00:00
|
|
|
arena(arena),
|
|
|
|
kTag(kt),
|
|
|
|
vTag(vt) {};
|
|
|
|
|
|
|
|
bool Lookup(const char *key, uint8_t klen, TLV::Record &res);
|
|
|
|
int Set(const char *key, uint8_t klen, const char *val,
|
|
|
|
uint8_t vlen);
|
|
|
|
bool Has(const char *key, uint8_t klen);
|
|
|
|
void DumpKVPairs();
|
|
|
|
void DumpToFile(const char *path);
|
2023-10-06 03:13:46 +00:00
|
|
|
private:
|
|
|
|
uint8_t *seek(const char *key, uint8_t klen);
|
2023-10-06 06:08:35 +00:00
|
|
|
bool spaceAvailable(uint8_t klen, uint8_t vlen);
|
2023-10-06 03:13:46 +00:00
|
|
|
|
|
|
|
Arena &arena;
|
2023-10-06 06:08:35 +00:00
|
|
|
uint8_t kTag;
|
|
|
|
uint8_t vTag;
|
2023-10-06 03:13:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|