|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
适用于不支持逆序写入的 Flash 存储的数据库实现 Database implementation for Flash storage that does not support reverse writing. More...
#include <raw_sequential.hpp>
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. | |
适用于不支持逆序写入的 Flash 存储的数据库实现 Database implementation for Flash storage that does not support reverse writing.
此类管理 Flash 内存区域中的键值存储,其中数据只能顺序写入。 它维护一个备份系统,以防止数据损坏。 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.
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.
|
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 99 of file raw_sequential.hpp.
|
overridevirtual |
获取数据库中的键值 Retrieve the key's value from the database.
| key | 需要获取的键 / Key to retrieve. |
ErrorCode::OK;键不存在返回 ErrorCode::NOT_FOUND;记录大小与键不一致返回 ErrorCode::FAILED Returns ErrorCode::OK if found with a matching size, ErrorCode::NOT_FOUND if the key does not exist, ErrorCode::FAILED if the stored size differs. Implements LibXR::Database.
Definition at line 136 of file raw_sequential.cpp.
| void DatabaseRawSequential::Init | ( | ) |
初始化数据库存储区,确保主备块正确 Initialize database storage, ensuring main and backup blocks are valid.
Definition at line 82 of file raw_sequential.cpp.
| void DatabaseRawSequential::Load | ( | ) |
从 Flash 加载数据到缓冲区 Load data from Flash into the buffer.
Definition at line 121 of file raw_sequential.cpp.
| void DatabaseRawSequential::Restore | ( | ) |
还原存储数据,清空 Flash 区域 Restore storage data, clearing Flash memory area.
Definition at line 123 of file raw_sequential.cpp.
| void DatabaseRawSequential::Save | ( | ) |
保存当前缓冲区内容到 Flash Save the current buffer content to Flash.
Definition at line 112 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 88 of file raw_sequential.hpp.