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.
|
|
|
|
package packet
|
|
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
// ErrWrongPacketType represents a wrong packet type.
|
|
|
|
|
ErrWrongPacketType = errors.New("wrong packet type")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
// IPacket 数据帧
|
|
|
|
|
IPacket interface {
|
|
|
|
|
GetHeader() interface{} // 数据帧头部 Header
|
|
|
|
|
GetLen() uint64 // 数据帧长度 8bytes,根据实际情况进行转换
|
|
|
|
|
GetBody() []byte // 数据 Body
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Packer 数据帧 封包/解包
|
|
|
|
|
Packer interface {
|
|
|
|
|
// Pack 封包,将原始数据构造为二进制流数据帧
|
|
|
|
|
Pack(header interface{}, data []byte) ([]byte, error)
|
|
|
|
|
|
|
|
|
|
// Unpack 解包
|
|
|
|
|
Unpack(data []byte) ([]IPacket, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NewPackerFunc func() Packer
|
|
|
|
|
)
|