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.
42 lines
750 B
Go
42 lines
750 B
Go
package packet
|
|
|
|
import "errors"
|
|
|
|
// Type 数据帧类型,如:握手,心跳,数据等
|
|
type Type byte
|
|
|
|
const (
|
|
// Default 默认,暂无意义
|
|
Default Type = iota
|
|
|
|
// Handshake 握手数据(服务端主动发起)
|
|
Handshake = 0x01
|
|
|
|
// HandshakeAck 握手回复(客户端回复)
|
|
HandshakeAck = 0x02
|
|
|
|
// Heartbeat 心跳(服务端发起)
|
|
Heartbeat = 0x03
|
|
|
|
// Data 数据传输
|
|
Data = 0x04
|
|
|
|
// Kick 服务端主动断开连接
|
|
Kick = 0x05
|
|
)
|
|
|
|
// ErrWrongPacketType represents a wrong packet type.
|
|
var ErrWrongPacketType = errors.New("wrong packet type")
|
|
|
|
type Packet struct {
|
|
Type Type // 数据帧 类型
|
|
Length uint32 // 数据长度
|
|
Data []byte // 原始数据
|
|
}
|
|
|
|
func New() *Packet {
|
|
return &Packet{
|
|
Type: Default,
|
|
}
|
|
}
|