packet

package
v0.0.56 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMessageIsNil    = errors.New("the message is nil")
	ErrSeqOverflow     = errors.New("the message seq overflow")
	ErrRouteOverflow   = errors.New("the message route overflow")
	ErrBufferOverflow  = errors.New("the message buffer overflow")
	ErrInvalidMessage  = errors.New("invalid message")
	ErrMessageTooLarge = errors.New("the message too large")
)

Functions

func Pack

func Pack(message *Message) ([]byte, error)

Pack 打包消息

func SetPacker

func SetPacker(packer Packer)

SetPacker 设置打包器

Types

type Message

type Message struct {
	Seq      int32 // 序列号
	Route    int32 // 路由ID
	Compress bool
	Buffer   []byte // 消息内容
}

func Unpack

func Unpack(data []byte) (*Message, error)

Unpack 解包消息

type Option

type Option func(o *options)

func WithBufferBytesLen

func WithBufferBytesLen(bufferBytesLen int) Option

WithBufferBytesLen 设置消息字节长度

func WithByteOrder

func WithByteOrder(byteOrder binary.ByteOrder) Option

WithByteOrder 设置字节序

func WithCompressBytesLen added in v0.0.8

func WithCompressBytesLen(compressBytesLen int) Option

WithCompressBytesLen 设置消息是否压缩标志位字节长度

func WithRouteBytesLen

func WithRouteBytesLen(routeBytesLen int) Option

WithRouteBytesLen 设置路由字节长度

func WithSeqBytesLen

func WithSeqBytesLen(seqBytesLen int) Option

WithSeqBytesLen 设置序列号字节长度

type Packer

type Packer interface {
	// Pack 打包消息
	Pack(message *Message) ([]byte, error)
	// Unpack 解包消息
	Unpack(data []byte) (*Message, error)
}

func GetPacker

func GetPacker() Packer

GetPacker 获取打包器

func NewPacker

func NewPacker(opts ...Option) Packer

Jump to

Keyboard shortcuts

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