7#include "interface.hpp"
134 KeyInfo(
bool nextKey, uint8_t nameLength, uint32_t dataSize);
174 static_assert(
sizeof(
KeyInfo) == 4,
"KeyInfo size must be 4 bytes");
187 ErrorCode AddKey(
const char* name,
const void* data,
size_t size);
188 ErrorCode SetKey(
const char* name,
const void* data,
size_t size);
189 ErrorCode SetKey(
size_t offset,
const void* data,
size_t size);
192 void ReadFlashOrExit(
size_t offset,
RawData data);
193 void WriteFlashOrExit(
size_t offset,
ConstRawData data);
194 void EraseFlashOrExit(
size_t offset,
size_t size);
198 bool HasLastKey(
size_t offset);
199 size_t GetKeySize(
size_t offset);
200 size_t GetNextKey(
size_t offset);
202 void SetNestKeyExist(
size_t offset,
bool exist);
203 bool KeyDataCompare(
size_t offset,
const void* data,
size_t size);
204 bool KeyNameCompare(
size_t offset,
const char* name);
205 size_t SearchKey(
const char* name);
只读原始数据视图 / Immutable raw data view
键的基类,存储键名及其数据 (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 w...
void Save()
保存当前缓冲区内容到 Flash (Save the current buffer content to Flash).
static constexpr uint8_t CHECKSUM_BYTE
校验字节 (Checksum byte).
ErrorCode Set(KeyBase &key, RawData data) override
设置数据库中的键值 (Set the key's value in the database).
uint32_t max_buffer_size_
最大缓冲区大小 (Maximum buffer size).
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).
uint8_t * buffer_
数据缓冲区 (Data buffer).
static constexpr uint32_t FLASH_HEADER
Flash 头部标识 (Flash header identifier).
ErrorCode Add(KeyBase &key) override
添加新键到数据库 (Add a new key to the database).
void Restore()
还原存储数据,清空 Flash 区域 (Restore storage data, clearing Flash memory area).
bool IsBlockEmpty(BlockType block)
判断块是否为空 (Check if block is empty).
uint32_t block_size_
Flash 块大小 (Flash block size).
Flash & flash_
目标 Flash 存储设备 (Target Flash storage device).
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).
bool IsBlockInited(BlockType block)
判断块是否已初始化 (Check if block is initialized).
BlockType
存储块类型 (Storage block type).
@ BACKUP
备份块 (Backup block).
bool IsBlockError(BlockType block)
判断块是否损坏 (Check if block has an error).
Abstract base class representing a flash memory interface. 抽象基类,表示闪存接口。
可写原始数据视图 / Mutable raw data view
size_t size_
数据字节数 / Data size in bytes
void * addr_
数据起始地址 / Data start address
static constexpr uint16_t LIBXR_DATABASE_VERSION
数据库存储格式版本号 (Database storage-format version).
Flash 存储的块信息结构 (Structure representing a Flash storage block).
KeyInfo key
该块的键信息 (Key metadata in this block).
uint32_t header
Flash 块头标识 (Flash block header identifier).
键信息结构,存储键的元数据 (Structure containing key metadata).
uint8_t GetNameLength() const
获取键名长度 (Get the key name length).
void SetNameLength(uint8_t len)
设置键名长度 (Set the key name length).
uint32_t GetDataSize() const
获取数据字节数 (Get the payload size in bytes).
KeyInfo()
构造一个擦除态键头 (Construct one erased-state key header).
void SetNextKeyExist(bool value)
设置是否存在后继键 (Set whether another key follows).
bool GetNextKeyExist() const
获取是否存在后继键 (Get whether another key follows).
void SetDataSize(uint32_t size)
设置数据字节数 (Set the payload size in bytes).