refactor(common): 重构 Pack 函数并优化数据处理
- 重构了 Pack 函数,支持处理不同类型的 data 参数 - 优化了数据打包过程,使用反射处理结构体和切片 - 修改了 TomeeHeader 结构体,使用 EnumCommandID 类型 - 调整了 login 相关的结构体定义 - 优化了 main 函数中的数据处理逻辑
This commit is contained in:
@@ -2,20 +2,21 @@ package handler
|
||||
|
||||
import (
|
||||
"blazing/common/serialize/bytearray"
|
||||
"blazing/common/socket/cmd"
|
||||
|
||||
"github.com/panjf2000/gnet/v2"
|
||||
)
|
||||
|
||||
// TomeeHeader 结构体字段定义
|
||||
type TomeeHeader struct {
|
||||
Len uint32 `json:"len"`
|
||||
Version string `json:"version" struc:"[1]byte"`
|
||||
CMD uint32 `json:"cmdId"`
|
||||
UserID uint32 `json:"userId"`
|
||||
Len uint32 `json:"len"`
|
||||
Version string `json:"version" struc:"[1]byte"`
|
||||
CMD cmd.EnumCommandID `json:"cmdId" struc:"uint32"`
|
||||
UserID uint32 `json:"userId"`
|
||||
//Error uint32 `json:"error" struc:"[0]pad"`
|
||||
|
||||
Result uint32 `json:"result"`
|
||||
Data []byte `json:"data"` //组包忽略此字段// struc:"[0]pad"
|
||||
Data []byte `json:"data" struc:"[0]pad"` //组包忽略此字段// struc:"[0]pad"
|
||||
}
|
||||
type TomeeHandler struct {
|
||||
Callback func(conn gnet.Conn, data TomeeHeader)
|
||||
@@ -34,7 +35,8 @@ func (h *TomeeHandler) Handle(c gnet.Conn, data []byte) { //处理接收到的
|
||||
tempdata := bytearray.CreateByteArray(data)
|
||||
header.Len, _ = tempdata.ReadUInt32()
|
||||
header.Version, _ = tempdata.ReadString(1)
|
||||
header.CMD, _ = tempdata.ReadUInt32()
|
||||
_CMD, _ := tempdata.ReadUInt32()
|
||||
header.CMD = cmd.EnumCommandID(_CMD)
|
||||
header.UserID, _ = tempdata.ReadUInt32()
|
||||
|
||||
header.Result, _ = tempdata.ReadUInt32()
|
||||
|
||||
Reference in New Issue
Block a user