ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
ngl::db_buff Class Reference

数据库缓冲区管理类。 More...

#include <db_buff.h>

Public Member Functions

 db_buff ()
 默认构造函数。
char * buff ()
 获取缓冲区数据指针。
int32_t buffsize ()
 获取缓冲区大小。
int32_t pos ()
 获取当前读写位置。
void reset () noexcept
 重置缓冲区状态。
template<typename T>
bool do_binary (T &adata, dbuff *abuff)
 执行二进制序列化。
template<typename T>
bool serialize (bool isbinary, T &adata)
 序列化数据。
template<typename T>
bool unserialize (bool isbinary, T &adata, const char *abuff, std::size_t alen)
 反序列化数据。

Detailed Description

数据库缓冲区管理类。

管理数据库查询结果的缓冲区,支持二进制和JSON两种序列化模式。 提供动态缓冲区分配和重用机制,优化内存使用效率。

Note
禁止拷贝构造和赋值操作。

Constructor & Destructor Documentation

◆ db_buff()

ngl::db_buff::db_buff ( )
inline

默认构造函数。

初始化内联缓冲区,默认大小为10MB。

Member Function Documentation

◆ buff()

char * ngl::db_buff::buff ( )
inline

获取缓冲区数据指针。

如果存在动态分配的缓冲区,则返回其指针; 否则返回内联缓冲区的指针。

Returns
缓冲区数据指针

◆ buffsize()

int32_t ngl::db_buff::buffsize ( )
inline

获取缓冲区大小。

Returns
缓冲区大小(字节)

◆ do_binary()

template<typename T>
bool ngl::db_buff::do_binary ( T & adata,
dbuff * abuff )
inline

执行二进制序列化。

将数据序列化到指定的缓冲区中。

Template Parameters
T数据类型
Parameters
adata要序列化的数据
abuff目标缓冲区
Returns
序列化成功返回true,否则返回false

◆ pos()

int32_t ngl::db_buff::pos ( )
inline

获取当前读写位置。

Returns
当前读写位置

◆ reset()

void ngl::db_buff::reset ( )
inlinenoexcept

重置缓冲区状态。

释放动态分配的缓冲区(如果有),并重置内联缓冲区的位置。

◆ serialize()

template<typename T>
bool ngl::db_buff::serialize ( bool isbinary,
T & adata )
inline

序列化数据。

根据指定的模式(二进制或JSON)序列化数据。 二进制模式:先尝试内联缓冲区,失败则使用动态分配的缓冲区。 JSON模式:将数据转换为JSON字符串并存储。

Template Parameters
T数据类型
Parameters
isbinary是否为二进制模式
adata要序列化的数据
Returns
序列化成功返回true,否则返回false

◆ unserialize()

template<typename T>
bool ngl::db_buff::unserialize ( bool isbinary,
T & adata,
const char * abuff,
std::size_t alen )
inline

反序列化数据。

根据指定的模式(二进制或JSON)从缓冲区反序列化数据。

Template Parameters
T数据类型
Parameters
isbinary是否为二进制模式
adata输出参数,存储反序列化的数据
abuff源缓冲区
alen缓冲区长度
Returns
反序列化成功返回true,否则返回false

The documentation for this class was generated from the following file: