ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
ngl::net_pack< T > Class Template Reference

网络数据包封装模板类。 More...

#include <net_pack.h>

Static Public Member Functions

template<typename Y>
static std::shared_ptr< packnpack (bpool *apool, const Y &adata, i64_actorid aactorid, i64_actorid arequestactorid, bool ahead)
 创建网络数据包。

Detailed Description

template<typename T>
class ngl::net_pack< T >

网络数据包封装模板类。

提供将任意类型的数据序列化为网络数据包的功能。 支持自定义序列化格式,通过模板参数T指定序列化策略。

Template Parameters
T序列化策略类型,决定数据的序列化方式
Note
该类不可实例化,所有方法都是静态的。
使用bpool进行内存管理,避免频繁的内存分配和释放。

Member Function Documentation

◆ npack()

template<typename T>
template<typename Y>
std::shared_ptr< pack > ngl::net_pack< T >::npack ( bpool * apool,
const Y & adata,
i64_actorid aactorid,
i64_actorid arequestactorid,
bool ahead )
inlinestatic

创建网络数据包。

将数据序列化为网络传输格式,并创建包含包头和载荷的完整数据包。

Template Parameters
Y要序列化的数据类型
Parameters
apool内存池指针,用于分配数据包内存
adata要序列化的数据
aactorid发送方Actor ID
arequestactorid请求方Actor ID
ahead是否包含包头
Returns
创建成功返回数据包共享指针,失败返回nullptr
Note
先计算序列化载荷大小,使pack::make_pack()可以一次性分配。
structbytes将pack头部和序列化载荷一起写入缓冲区。

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