7#include "interface.hpp"
108 enum class BlockType : uint8_t
136 KeyInfo(
bool nextKey, uint8_t nameLength, uint32_t dataSize);
142 void SetNextKeyExist(
bool value);
149 bool GetNextKeyExist()
const;
155 void SetNameLength(uint8_t len);
161 uint8_t GetNameLength()
const;
167 void SetDataSize(uint32_t size);
173 uint32_t GetDataSize()
const;
176 static_assert(
sizeof(
KeyInfo) == 4,
"KeyInfo size must be 4 bytes");
189 ErrorCode AddKey(
const char* name,
const void* data,
size_t size);
190 ErrorCode SetKey(
const char* name,
const void* data,
size_t size);
191 ErrorCode SetKey(
size_t offset,
const void* data,
size_t size);
192 ErrorCode GetKeyData(
size_t offset, RawData data);
193 void InitBlock(BlockType block);
194 void ReadFlashOrExit(
size_t offset, RawData data);
195 void WriteFlashOrExit(
size_t offset, ConstRawData data);
196 void EraseFlashOrExit(
size_t offset,
size_t size);
197 bool IsBlockInited(BlockType block);
198 bool IsBlockEmpty(BlockType block);
199 bool IsBlockError(BlockType block);
200 bool HasLastKey(
size_t offset);
201 size_t GetKeySize(
size_t offset);
202 size_t GetNextKey(
size_t offset);
203 size_t GetLastKey(BlockType block);
204 void SetNestKeyExist(
size_t offset,
bool exist);
205 bool KeyDataCompare(
size_t offset,
const void* data,
size_t size);
206 bool KeyNameCompare(
size_t offset,
const char* name);
207 size_t SearchKey(
const char* name);
209 static constexpr uint32_t FLASH_HEADER =
211 static constexpr uint8_t CHECKSUM_BYTE = 0x56;
215 uint32_t block_size_;
216 uint32_t max_buffer_size_;
键的基类,存储键名及其数据 Base class for keys, storing key name and associated data.
RawData raw_data_
原始数据 / Raw data associated with the key.
const char * name_
键名 / Key name.
数据库接口,提供键值存储和管理功能 Database interface providing key-value storage and management.
适用于不支持逆序写入的 Flash 存储的数据库实现 Database implementation for Flash storage that does not support reverse wr...
void Save()
保存当前缓冲区内容到 Flash Save the current buffer content to Flash.
ErrorCode Set(KeyBase &key, RawData data) override
设置数据库中的键值 Set the key's value in the database.
ErrorCode Get(Database::KeyBase &key) override
获取数据库中的键值 Retrieve the key's value from the database.
void Init()
初始化数据库存储区,确保主备块正确 Initialize database storage, ensuring main and backup blocks are valid.
ErrorCode Add(KeyBase &key) override
添加新键到数据库 Add a new key to the database.
void Restore()
还原存储数据,清空 Flash 区域 Restore storage data, clearing Flash memory area.
void Load()
从 Flash 加载数据到缓冲区 Load data from Flash into the buffer.
DatabaseRawSequential(Flash &flash, size_t max_buffer_size=256)
构造函数,初始化 Flash 存储和缓冲区 Constructor initializing Flash storage and buffer.
抽象基类,表示闪存接口。 Abstract base class representing a flash memory interface.
可写原始数据视图 / Mutable raw data view
size_t size_
数据字节数 / Data size in bytes
void * addr_
数据起始地址 / Data start address
LibXR 命名空间 / LibXR namespace.
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
static constexpr uint16_t LIBXR_DATABASE_VERSION
数据库存储格式版本号 Database storage-format version.
Flash 存储的块信息结构 Structure representing a Flash storage block.
键信息结构,存储键的元数据 Structure containing key metadata.