packet

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckHeartbeat added in v2.1.0

func CheckHeartbeat(data []byte) (bool, error)

CheckHeartbeat 检测心跳包

func NewPacker

func NewPacker(opts ...Option) *defaultPacker

func PackBuffer added in v2.1.0

func PackBuffer(message *Message) (buffer.Buffer, error)

PackBuffer 打包消息

func PackHeartbeat added in v2.1.0

func PackHeartbeat() ([]byte, error)

PackHeartbeat 打包心跳

func PackMessage added in v2.1.0

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

PackMessage 打包消息

func ReadMessage added in v2.1.0

func ReadMessage(reader interface{}) ([]byte, error)

ReadMessage 读取消息

func SetPacker

func SetPacker(packer Packer)

SetPacker 设置打包器

Types

type Message

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

func UnpackMessage added in v2.1.0

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

UnpackMessage 解包消息

type NocopyReader added in v2.1.0

type NocopyReader interface {
	// Next returns a slice containing the next n bytes from the buffer,
	// advancing the buffer as if the bytes had been returned by Read.
	Next(n int) (p []byte, err error)

	// Peek returns the next n bytes without advancing the reader.
	Peek(n int) (buf []byte, err error)

	// Release the memory space occupied by all read slices.
	Release() (err error)

	Slice(n int) (r NocopyReader, err error)
}

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 WithHeartbeatTime added in v2.1.0

func WithHeartbeatTime(heartbeatTime bool) Option

WithHeartbeatTime 是否携带心跳时间

func WithRouteBytes

func WithRouteBytes(routeBytes int) Option

WithRouteBytes 设置路由字节数

func WithSeqBytes

func WithSeqBytes(seqBytes int) Option

WithSeqBytes 设置序列号字节数

type Packer

type Packer interface {
	// ReadMessage 读取消息
	ReadMessage(reader interface{}) ([]byte, error)
	// PackBuffer 打包消息
	PackBuffer(message *Message) (buffer.Buffer, error)
	// PackMessage 打包消息
	PackMessage(message *Message) ([]byte, error)
	// UnpackMessage 解包消息
	UnpackMessage(data []byte) (*Message, error)
	// PackHeartbeat 打包心跳
	PackHeartbeat() ([]byte, error)
	// CheckHeartbeat 检测心跳包
	CheckHeartbeat(data []byte) (bool, error)
}

func GetPacker

func GetPacker() Packer

GetPacker 获取打包器

Jump to

Keyboard shortcuts

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