|
libxr
1.0
Want to be the best embedded framework
|
适用于不支持逆序写入的 Flash 存储的数据库实现 (Database implementation for Flash storage that does not support reverse writing). More...
#include <database.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 } |
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) |
| 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 内存区域中的键值存储,其中数据只能顺序写入。 它维护一个备份系统,以防止数据损坏。
Definition at line 158 of file database.hpp.
|
strongprivate |
| Enumerator | |
|---|---|
| MAIN | 主块 (Main block). |
| BACKUP | 备份块 (Backup block). |
Definition at line 229 of file database.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). |
Definition at line 10 of file database.cpp.
|
inlineoverridevirtual |
添加新键到数据库 (Add a new key to the database).
| key | 需要添加的键 (Key to add). |
Implements LibXR::Database.
Definition at line 223 of file database.hpp.
|
private |
Definition at line 237 of file database.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 77 of file database.cpp.
|
private |
Definition at line 300 of file database.cpp.
|
private |
Definition at line 169 of file database.cpp.
|
private |
Definition at line 181 of file database.cpp.
|
private |
Definition at line 176 of file database.cpp.
|
private |
Definition at line 162 of file database.cpp.
| void DatabaseRawSequential::Init | ( | ) |
初始化数据库存储区,确保主备块正确 (Initialize database storage, ensuring main and backup blocks are valid).
Definition at line 25 of file database.cpp.
|
private |
Definition at line 98 of file database.cpp.
|
private |
判断块是否为空 (Check if block is empty).
| block | 需要检查的块 (Block to check). |
Definition at line 133 of file database.cpp.
|
private |
判断块是否损坏 (Check if block has an error).
| block | 需要检查的块 (Block to check). |
Definition at line 150 of file database.cpp.
|
private |
判断块是否已初始化 (Check if block is initialized).
| block | 需要检查的块 (Block to check). |
Definition at line 116 of file database.cpp.
|
private |
Definition at line 204 of file database.cpp.
|
private |
Definition at line 221 of file database.cpp.
| void DatabaseRawSequential::Load | ( | ) |
从 Flash 加载数据到缓冲区 (Load data from Flash into the buffer).
Definition at line 64 of file database.cpp.
| void DatabaseRawSequential::Restore | ( | ) |
还原存储数据,清空 Flash 区域 (Restore storage data, clearing Flash memory area).
Definition at line 66 of file database.cpp.
| void DatabaseRawSequential::Save | ( | ) |
保存当前缓冲区内容到 Flash (Save the current buffer content to Flash).
Definition at line 55 of file database.cpp.
|
private |
Definition at line 313 of file database.cpp.
设置数据库中的键值 (Set the key's value in the database).
| key | 目标键 (Target key). |
| data | 需要存储的新值 (New value to store). |
Implements LibXR::Database.
Definition at line 212 of file database.hpp.
|
private |
Definition at line 270 of file database.cpp.
|
private |
Definition at line 279 of file database.cpp.
|
private |
Definition at line 196 of file database.cpp.
|
private |
Definition at line 308 of file database.hpp.
|
private |
数据缓冲区 (Data buffer).
Definition at line 307 of file database.hpp.
|
staticconstexprprivate |
校验字节 (Checksum byte).
Definition at line 304 of file database.hpp.
|
private |
目标 Flash 存储设备 (Target Flash storage device).
Definition at line 306 of file database.hpp.
|
staticconstexprprivate |
Flash 头部标识 (Flash header identifier).
Definition at line 302 of file database.hpp.
|
private |
最大缓冲区大小 (Maximum buffer size).
Definition at line 309 of file database.hpp.