packet

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 6 Imported by: 2

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")
)

Functions

func Pack

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

Pack 打包消息

func SetPacker added in v0.0.4

func SetPacker(packer Packer)

SetPacker 设置打包器

Types

type Message

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

func Unpack

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

Unpack 解包消息

type Option added in v0.0.4

type Option func(o *options)

func WithByteOrder added in v0.0.4

func WithByteOrder(byteOrder binary.ByteOrder) Option

WithByteOrder 设置字节序

func WithRouteBytesLen added in v0.0.4

func WithRouteBytesLen(routeBytesLen int) Option

WithRouteBytesLen 设置路由字节长度

func WithSeqBytesLen added in v0.0.4

func WithSeqBytesLen(seqBytesLen int) Option

WithSeqBytesLen 设置序列号字节长度

type Packer added in v0.0.4

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

func GetPacker added in v0.0.4

func GetPacker() Packer

GetPacker 获取打包器

func NewPacker added in v0.0.4

func NewPacker(opts ...Option) Packer

Jump to

Keyboard shortcuts

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