packet

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: Apache-2.0 Imports: 6 Imported by: 1

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

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

type Option func(o *options)

func WithByteOrder

func WithByteOrder(byteOrder binary.ByteOrder) Option

WithByteOrder 设置字节序

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