You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nnet/packet/packet.go

49 lines
910 B
Go

package packet
import (
"fmt"
)
// Type 数据帧类型,如:握手,心跳,数据等
type Type byte
const (
// Default 默认,暂无意义
Default Type = iota
// Handshake 握手数据(服务端主动发起)
Handshake = 0x01
// HandshakeAck 握手回复(客户端回复)
HandshakeAck = 0x02
// Heartbeat 心跳(服务端发起)
Heartbeat = 0x03
// Data 数据传输
Data = 0x04
// Kick 服务端主动断开连接
Kick = 0x05
)
type Packet struct {
Type Type // 数据帧 类型
HeaderLen uint32 // 数据帧头 长度
HeaderRaw []byte // 头原始数据
DataLen uint32 // 数据长度
DataRaw []byte // 原始数据
}
func New() *Packet {
return &Packet{
Type: Default,
}
}
func (p *Packet) String() string {
return fmt.Sprintf("Type: %d, HeaderLen: %d, DataLen: %d, Header: %s, Data: %s", p.Type, p.HeaderLen, p.DataLen, string(p.HeaderRaw), string(p.DataRaw))
}