libxr
1.0
Want to be the best embedded framework
|
适用于最小写入单元受限的 Flash 存储的数据库实现 (Database implementation for Flash storage with minimum write unit restrictions). More...
#include <database.hpp>
Data Structures | |
struct | BlockBoolData |
class | BlockBoolUtil |
struct | FlashInfo |
Flash 存储的块信息结构 (Structure representing a Flash storage block). More... | |
struct | KeyInfo |
键信息结构,存储键的元数据 (Structure containing key metadata). More... | |
Public Member Functions | |
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). | |
DatabaseRaw (Flash &flash, size_t recycle_threshold=128) | |
构造函数,初始化 Flash 存储和缓冲区 (Constructor to initialize Flash storage and buffer). | |
void | Init () |
初始化数据库存储区,确保主备块正确 (Initialize database storage, ensuring main and backup blocks are valid). | |
void | Restore () |
还原存储数据,清空 Flash 区域 (Restore storage data, clearing Flash memory area). | |
ErrorCode | Recycle () |
回收 Flash 空间,整理数据 (Recycle Flash storage space and organize data). | |
Private Types | |
enum class | BlockType : uint8_t { MAIN = 0 , BACKUP = 1 } |
Private Member Functions | |
size_t | AvailableSize () |
计算可用的存储空间大小 (Calculate the available storage size). | |
ErrorCode | AddKeyBody (size_t name_len, size_t size, size_t &key_buf_offset) |
ErrorCode | AddKey (size_t name_offset, size_t name_len, const void *data, size_t size) |
ErrorCode | AddKey (const char *name, const void *data, size_t size) |
ErrorCode | SetKeyCommon (size_t key_offset, size_t name_len, const void *data, size_t size) |
ErrorCode | SetKey (size_t name_offset, size_t name_length, const void *data, size_t size) |
ErrorCode | SetKey (const char *name, const void *data, size_t size, bool recycle=true) |
size_t | GetKeyData (size_t offset) |
size_t | GetKeyName (size_t offset) |
void | InitBlock (BlockType block) |
bool | IsBlockInited (BlockType block) |
bool | IsBlockEmpty (BlockType block) |
bool | IsBlockError (BlockType block) |
size_t | GetKeySize (size_t offset) |
size_t | GetNextKey (size_t offset) |
size_t | GetLastKey (BlockType block) |
bool | KeyDataCompare (size_t offset, const void *data, size_t size) |
bool | KeyNameCompare (size_t offset, const char *name) |
bool | KeyNameCompare (size_t offset_a, size_t offset_b) |
void | CopyFlashData (size_t dst_offset, size_t src_offset, size_t size) |
size_t | SearchKey (const char *name) |
size_t | AlignSize (size_t size) |
计算对齐后的大小 (Calculate the aligned size). | |
ErrorCode | Write (size_t offset, ConstRawData data) |
以最小写入单元对齐的方式写入数据 (Write data aligned to the minimum write unit). | |
Private Attributes | |
size_t | recycle_threshold_ = 0 |
回收阈值 (Recycle threshold). | |
Flash & | flash_ |
目标 Flash 存储设备 (Target Flash storage device). | |
uint32_t | block_size_ |
Flash 块大小 (Flash block size). | |
uint8_t | write_buffer_ [MinWriteSize] |
写入缓冲区 (Write buffer). | |
Static Private Attributes | |
static constexpr uint32_t | FLASH_HEADER |
Flash 头部标识 (Flash header identifier). | |
static constexpr uint32_t | CHECKSUM_BYTE = 0x9abcedf0 |
校验字节 (Checksum byte). | |
适用于最小写入单元受限的 Flash 存储的数据库实现 (Database implementation for Flash storage with minimum write unit restrictions).
This class provides key-value storage management for Flash memory that requires data to be written in fixed-size blocks. 此类提供适用于 Flash 存储的键值存储管理,该存储要求数据以固定大小块写入。
Definition at line 325 of file database.hpp.
|
strongprivate |
Enumerator | |
---|---|
MAIN | 主块 (Main block). |
BACKUP | 备份块 (Backup block). |
Definition at line 332 of file database.hpp.
|
inlineexplicit |
构造函数,初始化 Flash 存储和缓冲区 (Constructor to initialize Flash storage and buffer).
flash | 目标 Flash 存储设备 (Target Flash storage device). |
recycle_threshold | 回收阈值 (Recycle threshold). |
Definition at line 968 of file database.hpp.
|
inlineoverridevirtual |
添加新键到数据库 (Add a new key to the database).
key | 需要添加的键 (Key to add). |
Implements LibXR::Database.
Definition at line 956 of file database.hpp.
|
inlineprivate |
Definition at line 558 of file database.hpp.
|
inlineprivate |
Definition at line 545 of file database.hpp.
|
inlineprivate |
Definition at line 471 of file database.hpp.
|
inlineprivate |
计算对齐后的大小 (Calculate the aligned size).
size | 需要对齐的大小 (Size to align). |
Definition at line 875 of file database.hpp.
|
inlineprivate |
计算可用的存储空间大小 (Calculate the available storage size).
Definition at line 465 of file database.hpp.
|
inlineprivate |
Definition at line 813 of file database.hpp.
|
inlineoverridevirtual |
获取数据库中的键值 (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 922 of file database.hpp.
|
inlineprivate |
|
inlineprivate |
Definition at line 661 of file database.hpp.
|
inlineprivate |
|
inlineprivate |
Definition at line 736 of file database.hpp.
|
inlineprivate |
Definition at line 729 of file database.hpp.
|
inline |
初始化数据库存储区,确保主备块正确 (Initialize database storage, ensuring main and backup blocks are valid).
Definition at line 982 of file database.hpp.
|
inlineprivate |
Definition at line 663 of file database.hpp.
|
inlineprivate |
Definition at line 697 of file database.hpp.
|
inlineprivate |
Definition at line 709 of file database.hpp.
|
inlineprivate |
Definition at line 685 of file database.hpp.
|
inlineprivate |
Definition at line 758 of file database.hpp.
|
inlineprivate |
Definition at line 775 of file database.hpp.
|
inlineprivate |
Definition at line 791 of file database.hpp.
|
inline |
回收 Flash 空间,整理数据 (Recycle Flash storage space and organize data).
Moves valid keys from the main block to the backup block and erases the main block. 将主存储块中的有效键移动到备份块,并擦除主存储块。
Definition at line 1057 of file database.hpp.
|
inline |
还原存储数据,清空 Flash 区域 (Restore storage data, clearing Flash memory area).
Definition at line 1041 of file database.hpp.
|
inlineprivate |
Definition at line 822 of file database.hpp.
|
inlineoverridevirtual |
设置数据库中的键值 (Set the key's value in the database).
key | 目标键 (Target key). |
data | 需要存储的新值 (New value to store). |
Implements LibXR::Database.
Definition at line 950 of file database.hpp.
|
inlineprivate |
Definition at line 611 of file database.hpp.
|
inlineprivate |
Definition at line 605 of file database.hpp.
|
inlineprivate |
Definition at line 576 of file database.hpp.
|
inlineprivate |
以最小写入单元对齐的方式写入数据 (Write data aligned to the minimum write unit).
offset | 写入偏移量 (Write offset). |
data | 要写入的数据 (Data to write). |
Definition at line 887 of file database.hpp.
|
private |
Definition at line 457 of file database.hpp.
|
staticconstexprprivate |
校验字节 (Checksum byte).
Definition at line 330 of file database.hpp.
|
private |
目标 Flash 存储设备 (Target Flash storage device).
Definition at line 456 of file database.hpp.
|
staticconstexprprivate |
Flash 头部标识 (Flash header identifier).
Definition at line 327 of file database.hpp.
|
private |
回收阈值 (Recycle threshold).
Definition at line 455 of file database.hpp.
|
private |
写入缓冲区 (Write buffer).
Definition at line 458 of file database.hpp.