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

每个帧TCP/KCP数据包前置的固定大小线路头部。 More...

#include <pack_head.h>

Public Member Functions

 pack_head ()
 默认构造函数。
void set_mask ()
 设置当前头部的掩码。
EPH_HEAD_VAL check_mask () const
 验证当前头部的掩码。
void set_time ()
 设置当前头部的时间戳。
i32_time get_time () const
 获取当前头部的时间戳。
void set_actor (i64_actorid aactor, i64_actorid arequestactorid)
 设置当前头部的目标/源actor ID。
void set_requestactor (i64_actorid arequestactorid)
 设置当前头部的源actor ID。
i64_actorid get_actor () const
 从头部读取目标actor ID。
i64_actorid get_request_actor () const
 从头部读取源actor ID。
i16_actortype get_actortype () const
 打包的目标actor guid的便捷访问器。
i16_actortype get_request_actortype () const
 打包的源actor guid的便捷访问器。
i16_area get_actorarea () const
 目标actor区域/分片。
i32_actordataid get_actordataid () const
 目标actor本地数值ID。
void reset ()
 清除部分读取状态和所有头部字段。
int32_t getvalue (EPH aeph) const
 帧代码使用的原始槽位访问器。
int32_t get_bytes () const
 声明的有效载荷字节数。
EPH_HEAD_VAL isready () const
 报告掩码/头部是完整的、仍在接收中还是无效的。
i32_protocolnum protocolnum () const
 头部中存储的协议号。
i32_protocolnum get_protocolnumber () const
 为旧调用点保留的别名。
void set_protocol (i32_protocolnum aprotocolnum)
 设置头部中存储的协议号。
EPH_HEAD_VAL push (const char *&abuff, int32_t &alen)
 将数据推送到头部。
bool push_format (ngl::ser::serialize_push *aserialize) const
 将头部数据推送到序列化器。
void reservebuff (char *abuff, int abufflen, std::pair< char *, int32_t > &apair)
 当调用方需要可写的有效载荷区间时,跳过头部前缀。

Static Public Member Functions

static void head_set_mask (int32_t *abuff)
 每个数据包前缀一个常量字节掩码,让接收方能够区分帧数据流量和临时telnet命令。
static EPH_HEAD_VAL head_check_mask (const int32_t *abuff, int awpos)
 在头部流式传入时验证帧掩码。
static void head_set_time (int32_t *abuff)
 将发送方的当前逻辑时间戳写入头部。
static i32_time head_get_time (const int32_t *abuff)
 从头部读取发送方时间戳。
static void head_set_actor (int32_t *abuff, i64_actorid aactor, i64_actorid arequestactorid)
 将目标/源actor ID写入头部。
static void head_set_actor (int32_t *abuff, i64_actorid aactor)
 将目标actor ID写入头部。
static int32_t size ()
 返回固定的序列化头部大小(字节)。
static std::shared_ptr< pack_headmake_pooled ()
 从内存池分配一个pack_head对象。
static std::shared_ptr< pack_headmake_pooled (const pack_head &other)
 从内存池分配一个pack_head对象,并拷贝其他对象的数据。

Public Attributes

int32_t m_data [EPH_SUM] = {0}
 头部以原始int32槽位存储,可直接复制到网络缓冲区中,无需额外的序列化层。
int32_t m_wpos = 0
 当前写入位置,用于跟踪头部接收进度。

Detailed Description

每个帧TCP/KCP数据包前置的固定大小线路头部。

数据包头部结构体,用于在TCP/KCP传输中标记数据包边界、携带时间戳、目标/源actor ID等信息。 头部以原始int32槽位存储,可直接复制到网络缓冲区中,无需额外的序列化层。 包含掩码验证、时间戳管理、actor ID读写等功能。

Constructor & Destructor Documentation

◆ pack_head()

ngl::pack_head::pack_head ( )

默认构造函数。

初始化写入位置为0,头部数据清零。

初始化数据包头部,将写入位置设置为0。

Member Function Documentation

◆ check_mask()

EPH_HEAD_VAL ngl::pack_head::check_mask ( ) const

验证当前头部的掩码。

检查数据包头部的掩码。

调用head_check_mask验证m_data的掩码字段。

Returns
掩码验证结果。

验证数据包头部的前m_wpos个字节是否为掩码值。

Returns
掩码验证结果:EPH_HEAD_MASK_SUCCESS或EPH_HEAD_MASK_FAIL

◆ get_actor()

i64_actorid ngl::pack_head::get_actor ( ) const

从头部读取目标actor ID。

获取发送方Actor ID。

Returns
目标actor ID。
发送方Actor ID

◆ get_actorarea()

i16_area ngl::pack_head::get_actorarea ( ) const

目标actor区域/分片。

获取发送方Actor区域。

Returns
目标actor区域ID。
发送方Actor区域

◆ get_actordataid()

i32_actordataid ngl::pack_head::get_actordataid ( ) const

目标actor本地数值ID。

获取发送方Actor数据ID。

Returns
目标actor本地数值ID。
发送方Actor数据ID

◆ get_actortype()

i16_actortype ngl::pack_head::get_actortype ( ) const

打包的目标actor guid的便捷访问器。

获取发送方Actor类型。

Returns
目标actor类型。
发送方Actor类型

◆ get_bytes()

int32_t ngl::pack_head::get_bytes ( ) const

声明的有效载荷字节数。

获取消息体字节数。

Returns
有效载荷字节数。
消息体字节数

◆ get_protocolnumber()

i32_protocolnum ngl::pack_head::get_protocolnumber ( ) const

为旧调用点保留的别名。

获取协议号(别名)。

Returns
协议号。
协议号

◆ get_request_actor()

i64_actorid ngl::pack_head::get_request_actor ( ) const

从头部读取源actor ID。

获取请求方Actor ID。

Returns
源actor ID。
请求方Actor ID

◆ get_request_actortype()

i16_actortype ngl::pack_head::get_request_actortype ( ) const

打包的源actor guid的便捷访问器。

获取请求方Actor类型。

Returns
源actor类型。
请求方Actor类型

◆ get_time()

i32_time ngl::pack_head::get_time ( ) const

获取当前头部的时间戳。

获取数据包时间戳。

调用head_get_time获取m_data的时间戳字段。

Returns
发送方时间戳。
时间戳值

◆ getvalue()

int32_t ngl::pack_head::getvalue ( EPH aeph) const

帧代码使用的原始槽位访问器。

获取指定偏移量的值。

Parameters
aeph头部字段枚举值。
Returns
对应字段的int32值。
Parameters
aeph偏移量(EPH枚举值)
Returns
指定偏移量的值

◆ head_check_mask()

EPH_HEAD_VAL ngl::pack_head::head_check_mask ( const int32_t * abuff,
int awpos )
static

在头部流式传入时验证帧掩码。

检查数据包头部缓冲区的掩码。

Parameters
abuff头部数据缓冲区指针。
awpos当前写入位置。
Returns
掩码验证结果,EPH_HEAD_MASK_SUCCESS表示成功,EPH_HEAD_MASK_FAIL表示失败。

验证数据包头部缓冲区的前awpos个字节是否为掩码值。

Parameters
abuff数据包头部缓冲区指针
awpos要检查的字节数
Returns
掩码验证结果:EPH_HEAD_MASK_SUCCESS或EPH_HEAD_MASK_FAIL

◆ head_get_time()

i32_time ngl::pack_head::head_get_time ( const int32_t * abuff)
static

从头部读取发送方时间戳。

从数据包头部缓冲区获取时间戳。

Parameters
abuff头部数据缓冲区指针。
Returns
发送方时间戳。
Parameters
abuff数据包头部缓冲区指针
Returns
时间戳值

◆ head_set_actor() [1/2]

void ngl::pack_head::head_set_actor ( int32_t * abuff,
i64_actorid aactor )
static

将目标actor ID写入头部。

设置发送方Actor ID到数据包头部缓冲区。

Parameters
abuff头部数据缓冲区指针。
aactor目标actor ID。

仅设置发送方的Actor ID到指定的数据包头部缓冲区中。

Parameters
abuff数据包头部缓冲区指针
aactor发送方Actor ID

◆ head_set_actor() [2/2]

void ngl::pack_head::head_set_actor ( int32_t * abuff,
i64_actorid aactor,
i64_actorid arequestactorid )
static

将目标/源actor ID写入头部。

设置Actor ID到数据包头部缓冲区。

Parameters
abuff头部数据缓冲区指针。
aactor目标actor ID。
arequestactorid源actor ID。

将发送方和请求方的Actor ID设置到指定的数据包头部缓冲区中。

Parameters
abuff数据包头部缓冲区指针
aactor发送方Actor ID
arequestactorid请求方Actor ID

◆ head_set_mask()

void ngl::pack_head::head_set_mask ( int32_t * abuff)
static

每个数据包前缀一个常量字节掩码,让接收方能够区分帧数据流量和临时telnet命令。

设置数据包头部缓冲区的掩码。

Parameters
abuff头部数据缓冲区指针。

将数据包头部缓冲区的前EPH_MASK_COUNT_BYTES个字节设置为掩码值。 掩码用于验证数据包头部的完整性。

Parameters
abuff数据包头部缓冲区指针

◆ head_set_time()

void ngl::pack_head::head_set_time ( int32_t * abuff)
static

将发送方的当前逻辑时间戳写入头部。

设置数据包头部缓冲区的时间戳。

Parameters
abuff头部数据缓冲区指针。

将当前系统时间设置到指定的数据包头部缓冲区中。

Parameters
abuff数据包头部缓冲区指针

◆ isready()

EPH_HEAD_VAL ngl::pack_head::isready ( ) const

报告掩码/头部是完整的、仍在接收中还是无效的。

检查数据包头部是否就绪。

Returns
头部状态:EPH_HEAD_SUCCESS表示完整,EPH_HEAD_FOLLOW表示仍在接收中,EPH_HEAD_MASK_FAIL表示无效。

验证数据包头部是否已完全接收并验证通过。

Returns
验证结果:EPH_HEAD_SUCCESS、EPH_HEAD_MASK_FAIL或EPH_HEAD_FOLLOW

◆ make_pooled() [1/2]

std::shared_ptr< pack_head > ngl::pack_head::make_pooled ( )
static

从内存池分配一个pack_head对象。

从内存池创建数据包头部。

Returns
分配的pack_head对象的shared_ptr。

从pack_head_pool中分配内存并创建数据包头部实例。 使用自定义删除器确保正确释放内存。

Returns
数据包头部共享指针,失败返回nullptr

◆ make_pooled() [2/2]

std::shared_ptr< pack_head > ngl::pack_head::make_pooled ( const pack_head & other)
static

从内存池分配一个pack_head对象,并拷贝其他对象的数据。

从内存池创建数据包头部(拷贝构造)。

Parameters
other要拷贝的pack_head对象。
Returns
分配的pack_head对象的shared_ptr。

从pack_head_pool中分配内存并创建数据包头部实例,使用拷贝构造。 使用自定义删除器确保正确释放内存。

Parameters
other要拷贝的数据包头部
Returns
数据包头部共享指针,失败返回nullptr

◆ protocolnum()

i32_protocolnum ngl::pack_head::protocolnum ( ) const

头部中存储的协议号。

获取协议号。

Returns
协议号。
协议号

◆ push()

EPH_HEAD_VAL ngl::pack_head::push ( const char *& abuff,
int32_t & alen )

将数据推送到头部。

推送数据到数据包头部。

Parameters
abuff数据缓冲区指针,会被更新为已处理的数据位置。
alen数据长度,会被更新为剩余未处理的数据长度。
Returns
头部状态:EPH_HEAD_MASK_SUCCESS表示成功,EPH_HEAD_MASK_FAIL表示失败,EPH_HEAD_FOLLOW表示仍在接收中。

将接收到的数据推送到数据包头部缓冲区中。 头部可能跨多次socket读取分片到达。

Parameters
abuff数据指针(引用,会更新位置)
alen数据长度(引用,会更新)
Returns
验证结果:EPH_HEAD_SUCCESS、EPH_HEAD_MASK_FAIL或EPH_HEAD_FOLLOW

◆ push_format()

bool ngl::pack_head::push_format ( ngl::ser::serialize_push * aserialize) const

将头部数据推送到序列化器。

序列化数据包头部。

Parameters
aserialize序列化器指针。
Returns
推送是否成功。

将数据包头部数据序列化到指定的序列化器中。

Parameters
aserialize序列化器指针
Returns
序列化成功返回true,否则返回false

◆ reservebuff()

void ngl::pack_head::reservebuff ( char * abuff,
int abufflen,
std::pair< char *, int32_t > & apair )

当调用方需要可写的有效载荷区间时,跳过头部前缀。

预留消息体缓冲区。

Parameters
abuff数据缓冲区指针。
abufflen数据缓冲区长度。
apair输出参数,包含有效载荷区间指针和长度。

在固定大小的数据包头部之后预留消息体区间。

Parameters
abuff缓冲区指针
abufflen缓冲区总长度
apair输出参数:消息体区间指针和长度

◆ reset()

void ngl::pack_head::reset ( )

清除部分读取状态和所有头部字段。

重置数据包头部。

将m_data清零,m_wpos重置为0。

将数据包头部的所有数据清零,并将写入位置重置为0。

◆ set_actor()

void ngl::pack_head::set_actor ( i64_actorid aactor,
i64_actorid arequestactorid )

设置当前头部的目标/源actor ID。

设置Actor ID。

Parameters
aactor目标actor ID。
arequestactorid源actor ID。

设置数据包的发送方和请求方Actor ID。

Parameters
aactor发送方Actor ID
arequestactorid请求方Actor ID

◆ set_mask()

void ngl::pack_head::set_mask ( )

设置当前头部的掩码。

设置数据包头部的掩码。

调用head_set_mask设置m_data的掩码字段。

将数据包头部的前EPH_MASK_COUNT_BYTES个字节设置为掩码值。

◆ set_protocol()

void ngl::pack_head::set_protocol ( i32_protocolnum aprotocolnum)

设置头部中存储的协议号。

设置协议号。

Parameters
aprotocolnum协议号。
aprotocolnum协议号

◆ set_requestactor()

void ngl::pack_head::set_requestactor ( i64_actorid arequestactor)

设置当前头部的源actor ID。

设置请求方Actor ID。

Parameters
arequestactorid源actor ID。

仅设置数据包的请求方Actor ID。

Parameters
arequestactor请求方Actor ID

◆ set_time()

void ngl::pack_head::set_time ( )

设置当前头部的时间戳。

设置数据包时间戳。

调用head_set_time设置m_data的时间戳字段。

将当前系统时间设置到数据包头部中。

◆ size()

int32_t ngl::pack_head::size ( )
static

返回固定的序列化头部大小(字节)。

获取数据包头部大小。

Returns
头部大小(字节)。
数据包头部大小(字节)

Member Data Documentation

◆ m_data

int32_t ngl::pack_head::m_data[EPH_SUM] = {0}

头部以原始int32槽位存储,可直接复制到网络缓冲区中,无需额外的序列化层。

存储头部所有字段的原始int32数组,大小为EPH_SUM。

◆ m_wpos

int32_t ngl::pack_head::m_wpos = 0

当前写入位置,用于跟踪头部接收进度。

在流式接收头部时,记录已写入的字节数。


The documentation for this struct was generated from the following files: