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 | |
class | BlockBoolUtil |
struct | FlashInfo |
Flash 存储的块信息结构 (Structure representing a Flash storage block). More... | |
Public Member Functions | |
template<size_t BlockSize> | |
struct | __attribute__ ((packed)) BlockBoolData |
DatabaseRaw (Flash &flash) | |
构造函数,初始化 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). | |
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). | |
Private Member Functions | |
struct | __attribute__ ((packed)) |
键信息结构,存储键的元数据 (Structure containing key metadata). | |
template<size_t MinWriteSize> | |
struct LibXR::DatabaseRaw::FlashInfo | __attribute__ ((packed)) |
size_t | AvailableSize () |
计算可用的存储空间大小 (Calculate the available storage size). | |
ErrorCode | AddKey (const char *name, const void *data, size_t size) |
ErrorCode | SetKey (const char *name, const void *data, size_t size, bool recycle=true) |
uint8_t * | GetKeyData (KeyInfo *key) |
获取指定键的数据信息 (Retrieve the data associated with a key). | |
const char * | GetKeyName (KeyInfo *key) |
获取键的名称 (Retrieve the name of a key). | |
void | InitBlock (FlashInfo *block) |
bool | IsBlockInited (FlashInfo *block) |
bool | IsBlockEmpty (FlashInfo *block) |
bool | IsBlockError (FlashInfo *block) |
size_t | GetKeySize (KeyInfo *key) |
KeyInfo * | GetNextKey (KeyInfo *key) |
KeyInfo * | GetLastKey (FlashInfo *block) |
KeyInfo * | SearchKey (const char *name) |
ErrorCode | Add (KeyBase &key) override |
添加新键到数据库 (Add a new key to the database). | |
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 | |
KeyInfo | |
Flash & | flash_ |
目标 Flash 存储设备 (Target Flash storage device). | |
FlashInfo * | info_main_ |
主存储区信息 (Main storage block information). | |
FlashInfo * | info_backup_ |
备份存储区信息 (Backup storage block information). | |
uint32_t | block_size_ |
Flash 块大小 (Flash block size). | |
uint8_t * | write_buffer_ |
写入缓冲区 (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 322 of file database.hpp.
|
inlineexplicit |
构造函数,初始化 Flash 存储和缓冲区 (Constructor to initialize Flash storage and buffer).
Definition at line 387 of file database.hpp.
|
inlineprivate |
键信息结构,存储键的元数据 (Structure containing key metadata).
< 是否是最后一个键 (Indicates if this is the last key).
< 该键是否有效 (Indicates if this key is available).
< 该键是否未初始化 (Indicates if this key is uninitialized).
< 键名长度 (Length of the key name).
< 数据大小 (Size of the stored data).
Definition at line 455 of file database.hpp.
|
inline |
Definition at line 214 of file database.hpp.
|
inlineoverrideprivatevirtual |
添加新键到数据库 (Add a new key to the database).
key | 需要添加的键 (Key to add). |
Implements LibXR::Database.
Definition at line 799 of file database.hpp.
|
inlineprivate |
Definition at line 542 of file database.hpp.
|
inlineprivate |
计算对齐后的大小 (Calculate the aligned size).
size | 需要对齐的大小 (Size to align). |
Definition at line 810 of file database.hpp.
|
inlineprivate |
计算可用的存储空间大小 (Calculate the available storage size).
Definition at line 535 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 857 of file database.hpp.
|
inlineprivate |
获取指定键的数据信息 (Retrieve the data associated with a key).
key | 目标键 (Key to retrieve data from). |
Definition at line 682 of file database.hpp.
|
inlineprivate |
获取键的名称 (Retrieve the name of a key).
key | 目标键 (Key to retrieve the name from). |
Definition at line 694 of file database.hpp.
|
inlineprivate |
Definition at line 744 of file database.hpp.
|
inlineprivate |
Definition at line 753 of file database.hpp.
|
inlineprivate |
Definition at line 749 of file database.hpp.
|
inline |
初始化数据库存储区,确保主备块正确 (Initialize database storage, ensuring main and backup blocks are valid).
Definition at line 404 of file database.hpp.
|
inlineprivate |
Definition at line 709 of file database.hpp.
|
inlineprivate |
Definition at line 734 of file database.hpp.
|
inlineprivate |
Definition at line 738 of file database.hpp.
|
inlineprivate |
Definition at line 733 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 455 of file database.hpp.
|
inline |
还原存储数据,清空 Flash 区域 (Restore storage data, clearing Flash memory area).
Definition at line 444 of file database.hpp.
|
inlineprivate |
Definition at line 767 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 882 of file database.hpp.
|
inlineprivate |
Definition at line 632 of file database.hpp.
|
inlineprivate |
以最小写入单元对齐的方式写入数据 (Write data aligned to the minimum write unit).
offset | 写入偏移量 (Write offset). |
data | 要写入的数据 (Data to write). |
Definition at line 822 of file database.hpp.
|
private |
Definition at line 706 of file database.hpp.
|
staticconstexprprivate |
校验字节 (Checksum byte).
Definition at line 701 of file database.hpp.
|
private |
目标 Flash 存储设备 (Target Flash storage device).
Definition at line 703 of file database.hpp.
|
staticconstexprprivate |
Flash 头部标识 (Flash header identifier).
Definition at line 699 of file database.hpp.
|
private |
备份存储区信息 (Backup storage block information).
Definition at line 705 of file database.hpp.
|
private |
主存储区信息 (Main storage block information).
Definition at line 704 of file database.hpp.
|
private |
Definition at line 518 of file database.hpp.
|
private |
写入缓冲区 (Write buffer).
Definition at line 707 of file database.hpp.