packet

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 2 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWrongPacketType represents a wrong packet type.
	ErrWrongPacketType = errors.New("wrong packet type")
	// ErrPacketSizeExceed represents a wrong packet size.
	ErrPacketSizeExceed = errors.New("packet size exceed")
)

Functions

This section is empty.

Types

type IPacket

type IPacket interface {
	GetHeader() any  // 数据帧头部 Header
	GetLen() uint64  // 数据帧长度 8bytes,根据实际情况进行转换
	GetBody() []byte // 数据 Body
}

IPacket 数据帧

func NewWSPacket added in v1.1.4

func NewWSPacket(typ int, data []byte) IPacket

type Packer

type Packer interface {
	// Pack 封包,将原始数据构造为二进制流数据帧
	Pack(header any, data []byte) ([]byte, error)

	// Unpack 解包
	Unpack(data []byte) ([]IPacket, error)
}

Packer 数据帧 封包/解包

type PackerBuilder added in v0.7.0

type PackerBuilder func() Packer

PackerBuilder Packer构建器

type WSPacket added in v1.1.4

type WSPacket struct {
	MessageType int
	Len         uint64
	Raw         []byte
}

func (*WSPacket) GetBody added in v1.1.4

func (p *WSPacket) GetBody() []byte

func (*WSPacket) GetHeader added in v1.1.4

func (p *WSPacket) GetHeader() any

func (*WSPacket) GetLen added in v1.1.4

func (p *WSPacket) GetLen() uint64

func (*WSPacket) String added in v1.1.4

func (p *WSPacket) String() string

Jump to

Keyboard shortcuts

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