|
libxr
1.0
Want to be the best embedded framework
|
适用于不支持逆序写入的 Flash 存储的数据库实现 (Database implementation for Flash storage that does not support reverse writing). More...
#include <raw_sequential.hpp>
Data Structures | |
| struct | FlashInfo |
| Flash 存储的块信息结构 (Structure representing a Flash storage block). More... | |
| struct | KeyInfo |
| 键信息结构,存储键的元数据 (Structure containing key metadata). More... | |
Public Member Functions | |
| DatabaseRawSequential (Flash &flash, size_t max_buffer_size=256) | |
| 构造函数,初始化 Flash 存储和缓冲区 (Constructor initializing Flash storage and buffer). | |
| void | Init () |
| 初始化数据库存储区,确保主备块正确 (Initialize database storage, ensuring main and backup blocks are valid). | |
| void | Save () |
| 保存当前缓冲区内容到 Flash (Save the current buffer content to Flash). | |
| void | Load () |
| 从 Flash 加载数据到缓冲区 (Load data from Flash into the buffer). | |
| void | Restore () |
| 还原存储数据,清空 Flash 区域 (Restore storage data, clearing Flash memory area). | |
| ErrorCode | Get (Database::KeyBase &key) override |
| 获取数据库中的键值 (Retrieve the key's value from the database). | |
| ErrorCode | Set (KeyBase &key, RawData data) override |
| 设置数据库中的键值 (Set the key's value in the database). | |
| ErrorCode | Add (KeyBase &key) override |
| 添加新键到数据库 (Add a new key to the database). | |
Private Types | |
| enum class | BlockType : uint8_t { MAIN = 0 , BACKUP = 1 } |
| 存储块类型 (Storage block type). More... | |
Private Member Functions | |
| ErrorCode | AddKey (const char *name, const void *data, size_t size) |
| ErrorCode | SetKey (const char *name, const void *data, size_t size) |
| ErrorCode | SetKey (size_t offset, const void *data, size_t size) |
| ErrorCode | GetKeyData (size_t offset, RawData data) |
| void | InitBlock (BlockType block) |
| void | ReadFlashOrExit (size_t offset, RawData data) |
| void | WriteFlashOrExit (size_t offset, ConstRawData data) |
| void | EraseFlashOrExit (size_t offset, size_t size) |
| bool | IsBlockInited (BlockType block) |
| 判断块是否已初始化 (Check if block is initialized). | |
| bool | IsBlockEmpty (BlockType block) |
| 判断块是否为空 (Check if block is empty). | |
| bool | IsBlockError (BlockType block) |
| 判断块是否损坏 (Check if block has an error). | |
| bool | HasLastKey (size_t offset) |
| size_t | GetKeySize (size_t offset) |
| size_t | GetNextKey (size_t offset) |
| size_t | GetLastKey (BlockType block) |
| void | SetNestKeyExist (size_t offset, bool exist) |
| bool | KeyDataCompare (size_t offset, const void *data, size_t size) |
| bool | KeyNameCompare (size_t offset, const char *name) |
| size_t | SearchKey (const char *name) |
Private Attributes | |
| Flash & | flash_ |
| 目标 Flash 存储设备 (Target Flash storage device). | |
| uint8_t * | buffer_ |
| 数据缓冲区 (Data buffer). | |
| uint32_t | block_size_ |
| Flash 块大小 (Flash block size). | |
| uint32_t | max_buffer_size_ |
| 最大缓冲区大小 (Maximum buffer size). | |
Static Private Attributes | |
| static constexpr uint32_t | FLASH_HEADER |
| Flash 头部标识 (Flash header identifier). | |
| static constexpr uint8_t | CHECKSUM_BYTE = 0x56 |
| 校验字节 (Checksum byte). | |
适用于不支持逆序写入的 Flash 存储的数据库实现 (Database implementation for Flash storage that does not support reverse writing).
This class manages key-value storage in a Flash memory region where data can only be written sequentially. It maintains a backup system to prevent data corruption. 此类管理 Flash 内存区域中的键值存储,其中数据只能顺序写入。 它维护一个备份系统,以防止数据损坏。
REQUIRE。 If the underlying Flash read, write, or erase operation fails, the current implementation treats it as an unrecoverable fault and triggers REQUIRE immediately. Definition at line 28 of file raw_sequential.hpp.
|
strongprivate |
存储块类型 (Storage block type).
| Enumerator | |
|---|---|
| MAIN | 主块 (Main block). |
| BACKUP | 备份块 (Backup block). |
Definition at line 107 of file raw_sequential.hpp.
|
explicit |
构造函数,初始化 Flash 存储和缓冲区 (Constructor initializing Flash storage and buffer).
| flash | 目标 Flash 存储设备 (Target Flash storage device). |
| max_buffer_size | 最大缓冲区大小,默认 256 字节 (Maximum buffer size, default is 256 bytes). |
max_buffer_size 必须不超过整片 Flash 容量的一半。 max_buffer_size must not exceed half of the total flash capacity. Definition at line 11 of file raw_sequential.cpp.
添加新键到数据库 (Add a new key to the database).
| key | 需要添加的键 (Key to add). |
Implements LibXR::Database.
Definition at line 98 of file raw_sequential.hpp.
|
private |
Definition at line 293 of file raw_sequential.cpp.
|
private |
Definition at line 74 of file raw_sequential.cpp.
|
overridevirtual |
获取数据库中的键值 (Retrieve the key's value from the database).
| key | 需要获取的键 (Key to retrieve). |
ErrorCode::OK,否则返回 ErrorCode::NOT_FOUND (Operation result, returns ErrorCode::OK if found, otherwise ErrorCode::NOT_FOUND). Implements LibXR::Database.
Definition at line 133 of file raw_sequential.cpp.
Definition at line 356 of file raw_sequential.cpp.
|
private |
Definition at line 225 of file raw_sequential.cpp.
|
private |
Definition at line 237 of file raw_sequential.cpp.
|
private |
Definition at line 232 of file raw_sequential.cpp.
|
private |
Definition at line 218 of file raw_sequential.cpp.
| void DatabaseRawSequential::Init | ( | ) |
初始化数据库存储区,确保主备块正确 (Initialize database storage, ensuring main and backup blocks are valid).
Definition at line 79 of file raw_sequential.cpp.
|
private |
Definition at line 154 of file raw_sequential.cpp.
|
private |
判断块是否为空 (Check if block is empty).
| block | 需要检查的块 (Block to check). |
Definition at line 189 of file raw_sequential.cpp.
|
private |
判断块是否损坏 (Check if block has an error).
| block | 需要检查的块 (Block to check). |
Definition at line 206 of file raw_sequential.cpp.
|
private |
判断块是否已初始化 (Check if block is initialized).
| block | 需要检查的块 (Block to check). |
Definition at line 172 of file raw_sequential.cpp.
|
private |
Definition at line 260 of file raw_sequential.cpp.
|
private |
Definition at line 277 of file raw_sequential.cpp.
| void DatabaseRawSequential::Load | ( | ) |
从 Flash 加载数据到缓冲区 (Load data from Flash into the buffer).
Definition at line 118 of file raw_sequential.cpp.
|
private |
Definition at line 64 of file raw_sequential.cpp.
| void DatabaseRawSequential::Restore | ( | ) |
还原存储数据,清空 Flash 区域 (Restore storage data, clearing Flash memory area).
Definition at line 120 of file raw_sequential.cpp.
| void DatabaseRawSequential::Save | ( | ) |
保存当前缓冲区内容到 Flash (Save the current buffer content to Flash).
Definition at line 109 of file raw_sequential.cpp.
|
private |
Definition at line 369 of file raw_sequential.cpp.
设置数据库中的键值 (Set the key's value in the database).
| key | 目标键 (Target key). |
| data | 需要存储的新值 (New value to store). |
Implements LibXR::Database.
Definition at line 87 of file raw_sequential.hpp.
|
private |
Definition at line 326 of file raw_sequential.cpp.
|
private |
Definition at line 335 of file raw_sequential.cpp.
|
private |
Definition at line 252 of file raw_sequential.cpp.
|
private |
Definition at line 69 of file raw_sequential.cpp.
|
private |
Definition at line 215 of file raw_sequential.hpp.
|
private |
数据缓冲区 (Data buffer).
Definition at line 214 of file raw_sequential.hpp.
|
staticconstexprprivate |
校验字节 (Checksum byte).
Definition at line 211 of file raw_sequential.hpp.
|
private |
目标 Flash 存储设备 (Target Flash storage device).
Definition at line 213 of file raw_sequential.hpp.
|
staticconstexprprivate |
Flash 头部标识 (Flash header identifier).
Definition at line 209 of file raw_sequential.hpp.
|
private |
最大缓冲区大小 (Maximum buffer size).
Definition at line 216 of file raw_sequential.hpp.