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) :
|
|
|
|
arena(arena),
|
|
|
|
ktag(PHONEBOOK_KEY_TAG),
|
|
|
|
vtag(PHONEBOOK_VAL_TAG) {} ;
|
|
|
|
Phonebook(Arena &arena, uint8_t kt, uint8_t vt) :
|
|
|
|
arena(arena),
|
|
|
|
ktag(kt),
|
|
|
|
vtag(vt) {};
|
|
|
|
|
|
|
|
bool lookup(const char *key, uint8_t klen, TLV::Record &res);
|
2023-10-06 04:18:21 +00:00
|
|
|
int set(const char *key, uint8_t klen, const char *val,
|
|
|
|
uint8_t vlen);
|
2023-10-06 03:13:46 +00:00
|
|
|
bool has(const char *key, uint8_t klen);
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t *seek(const char *key, uint8_t klen);
|
2023-10-06 04:18:21 +00:00
|
|
|
bool space_available(uint8_t klen, uint8_t vlen);
|
2023-10-06 03:13:46 +00:00
|
|
|
|
|
|
|
Arena &arena;
|
|
|
|
uint8_t ktag;
|
|
|
|
uint8_t vtag;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|