packet

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 WithBufferBytes

func WithBufferBytes(bufferBytes int) Option

WithBufferBytes 设置消息字节数

func WithByteOrder

func WithByteOrder(byteOrder binary.ByteOrder) Option

WithByteOrder 设置字节序

func WithRouteBytes

func WithRouteBytes(routeBytes int) Option

WithRouteBytes 设置路由字节数

func WithSeqBytes

func WithSeqBytes(seqBytes int) Option

WithSeqBytes 设置序列号字节数

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