packet

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// 协议头长度
	HeaderLength = 8
	// 协议头标识
	HeaderFlag = 0x7E
	// 最大内容程度,16MBB
	MaxPacketSize = 1 << 24
)

Variables

View Source
var (
	GetPacket = _pool.GetPacket
	PutPacket = _pool.PutPacket
)
View Source
var ErrEncodeType = errors.New("wrong encode type")
View Source
var ErrHeaderFlag = errors.New("wrong header flag")
View Source
var ErrHeaderLength = errors.New("wrong header length")
View Source
var ErrMaxPacketSize = errors.New("max packet size")

Functions

func ActionToBytes

func ActionToBytes(action uint32) []byte

func CreateAction

func CreateAction(packetType PacketType, module uint8, action uint16) uint32

func CreateHeader

func CreateHeader(data []byte, version, encodeType uint8, action uint32) []byte

Types

type Packet

type Packet struct {
	Bean       interface{}
	HeaderByte []byte
	Data       []byte
}

5.6.7byte length: 24bit 消息长度

func NewPacket

func NewPacket(data []byte) *Packet

func NewPacketWithHeader

func NewPacketWithHeader(data []byte, version, encodeType uint8, action uint32) *Packet

func ParsePacket

func ParsePacket(data []byte) (*Packet, error)

ParsePacket 从字节数组中解析出Packet

func (*Packet) GetActionKey

func (p *Packet) GetActionKey() uint32

packetType: 2bit // 0x01: system, 0x02: service module: 6bit action: 16bit 合一起的值 协议头/2/3/4字节

func (*Packet) GetEncodeType

func (p *Packet) GetEncodeType() uint8

func (*Packet) GetLength

func (p *Packet) GetLength() uint32

func (*Packet) GetModule

func (p *Packet) GetModule() uint8

func (*Packet) GetPacketType

func (p *Packet) GetPacketType() PacketType

func (*Packet) GetVersion

func (p *Packet) GetVersion() uint8

func (*Packet) ToByte added in v0.1.6

func (p *Packet) ToByte() []byte

func (*Packet) ToData

func (p *Packet) ToData() *bytebuffer.ByteBuffer

type PacketType

type PacketType byte
const (
	// 系统内置包,如Ping Pong
	SystemPacket PacketType = 0x01
	// 服务类型包,如Login、Register
	ServicePacket PacketType = 0x02
)

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool() *Pool

func (Pool) GetPacket

func (p Pool) GetPacket() *Packet

func (Pool) PutPacket

func (p Pool) PutPacket(bean *Packet)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL