codec

package
v0.3.68 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: LGPL-2.1 Imports: 7 Imported by: 1

Documentation

Overview

Package codec 提供 GAP 消息包的编解码能力。

这个包位于 GAP 协议的线格式层,负责把 gap.MsgPacket 编码为字节流, 并在接收侧把字节流还原为对应的消息包对象。

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDecode 是 GAP 消息包解码错误的根错误。
	ErrDecode = errors.New("gap-decode")
)
View Source
var (
	// ErrEncode 是 GAP 消息包编码错误的根错误。
	ErrEncode = errors.New("gap-encode")
)

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	MsgCreator gap.IMsgCreator // 用于构造消息体的消息构建器。
}

Decoder 根据消息头中的类型 ID 构造并解码消息体。

func NewDecoder added in v0.3.35

func NewDecoder(msgCreator gap.IMsgCreator) *Decoder

NewDecoder 创建使用指定消息构建器的解码器;构建器不得为 nil。

func (*Decoder) Decode

func (d *Decoder) Decode(data []byte) (gap.MsgPacket, error)

Decode 从 data 解码一个消息包;消息字段可能直接引用 data,调用方不得提前复用它。

type Encoder

type Encoder struct{}

Encoder 将 GAP 消息和来源信息编码为完整消息包。

func NewEncoder added in v0.3.35

func NewEncoder() *Encoder

NewEncoder 返回无状态的共享消息包编码器。

func (*Encoder) Encode

func (*Encoder) Encode(src gap.Origin, seq int64, msg gap.ReadableMsg) (ret binaryutil.Bytes, err error)

Encode 编码消息包并返回池化字节缓冲区;调用方使用完后必须调用 Release。

Jump to

Keyboard shortcuts

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