6#include "libxr_def.hpp"
19 ASSERT(
flash.min_erase_size_ * 2 <=
flash.flash_area_.size_);
103 {data_buffer_, block_size_});
124 return block->key.nameLength == 0;
134 return reinterpret_cast<uint8_t*
>(
145 return sizeof(KeyInfo) + key->nameLength + key->dataSize;
155 return reinterpret_cast<KeyInfo*
>(
reinterpret_cast<uint8_t*
>(key) +
GetKeySize(key));
171 KeyInfo* key = &
block->key;
201 return ErrorCode::FULL;
215 return ErrorCode::OK;
229 return SetKey(key, data, size);
231 return ErrorCode::FAILED;
250 ASSERT(key !=
nullptr);
252 if (key->dataSize == size)
259 return ErrorCode::OK;
262 return ErrorCode::FAILED;
276 return reinterpret_cast<uint8_t*
>(key) +
sizeof(KeyInfo) + key->nameLength;
290 return reinterpret_cast<const char*
>(key) +
sizeof(KeyInfo);
void Save()
保存当前缓冲区内容到 Flash (Save the current buffer content to Flash).
bool IsBlockInited(FlashInfo *block)
判断块是否已初始化 (Check if block is initialized).
static constexpr uint8_t CHECKSUM_BYTE
校验字节 (Checksum byte).
FlashInfo * info_backup_
备份存储区信息 (Backup storage block information).
uint32_t max_buffer_size_
最大缓冲区大小 (Maximum buffer size).
bool IsBlockError(FlashInfo *block)
判断块是否损坏 (Check if block has an error).
void Init()
初始化数据库存储区,确保主备块正确 (Initialize database storage, ensuring main and backup blocks are valid).
KeyInfo * SearchKey(const char *name)
查找键 (Search for key).
size_t GetKeySize(KeyInfo *key)
计算键的总大小 (Calculate total size of a key).
const char * GetKeyName(KeyInfo *key)
获取键的名称 (Retrieve the name of a key).
static constexpr uint32_t FLASH_HEADER
Flash 头部标识 (Flash header identifier).
bool IsBlockEmpty(FlashInfo *block)
判断块是否为空 (Check if block is empty).
void Restore()
还原存储数据,清空 Flash 区域 (Restore storage data, clearing Flash memory area).
uint8_t * GetKeyData(KeyInfo *key)
获取指定键的数据信息 (Retrieve the data associated with a key).
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).
FlashInfo * info_main_
主存储区信息 (Main storage block information).
DatabaseRawSequential(Flash &flash, size_t max_buffer_size=256)
构造函数,初始化 Flash 存储和缓冲区 (Constructor initializing Flash storage and buffer).
ErrorCode SetKey(const char *name, const void *data, size_t size)
设置键值 (Set key value).
KeyInfo * GetLastKey(FlashInfo *block)
获取块中的最后一个键 (Get last key in block).
KeyInfo * GetNextKey(KeyInfo *key)
获取下一个键 (Get next key).
uint8_t * data_buffer_
数据缓冲区 (Data buffer).
void InitBlock(FlashInfo *block)
初始化块数据 (Initialize block data).
ErrorCode AddKey(const char *name, const void *data, size_t size)
添加键值对到数据库 (Add key-value pair to database).
FlashInfo * flash_data_
Flash 数据存储区 (Pointer to the Flash data storage).
Abstract base class representing a flash memory interface. 抽象基类,表示闪存接口。
virtual ErrorCode Erase(size_t offset, size_t size)=0
Erases a section of the flash memory. 擦除闪存的指定区域。
virtual ErrorCode Write(size_t offset, ConstRawData data)=0
Writes data to the flash memory. 向闪存写入数据。
void * addr_
数据存储地址。 The storage address of the data.
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
Flash 存储的块信息结构 (Structure representing a Flash storage block).
KeyInfo key
该块的键信息 (Key metadata in this block).
uint32_t header
Flash 块头标识 (Flash block header identifier).