codec

package
v0.2.26 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: LGPL-2.1 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIncorrectMAC = errors.New("gtp: incorrect MAC") // MAC值不正确
)

Functions

This section is empty.

Types

type CompressionModule

type CompressionModule struct {
	CompressionStream method.CompressionStream // 压缩流
}

CompressionModule 压缩模块

func (*CompressionModule) Compress

func (m *CompressionModule) Compress(src []byte) (dst binaryutil.RecycleBytes, compressed bool, err error)

Compress 压缩数据

func (*CompressionModule) Uncompress

func (m *CompressionModule) Uncompress(src []byte) (dst binaryutil.RecycleBytes, err error)

Uncompress 解压缩数据

type Decoder

type Decoder struct {
	MsgCreator        gtp.IMsgCreator    // 消息对象构建器
	EncryptionModule  IEncryptionModule  // 加密模块
	MACModule         IMACModule         // MAC模块
	CompressionModule ICompressionModule // 压缩模块
	// contains filtered or unexported fields
}

Decoder 消息包解码器

func (*Decoder) Decode

func (d *Decoder) Decode(data []byte, validate ...IValidate) (gtp.MsgPacket, int, error)

Decode 解码消息包

func (*Decoder) GC

func (d *Decoder) GC()

GC GC

type DecoderCreator

type DecoderCreator struct {
	// contains filtered or unexported fields
}

DecoderCreator 消息包解码器构建器

func CreateDecoder

func CreateDecoder(msgCreator gtp.IMsgCreator) DecoderCreator

CreateDecoder 创建消息包解码器

func (DecoderCreator) SetupCompressionModule

func (dc DecoderCreator) SetupCompressionModule(compressionModule ICompressionModule) DecoderCreator

SetupCompressionModule 安装压缩模块

func (DecoderCreator) SetupEncryptionModule

func (dc DecoderCreator) SetupEncryptionModule(encryptionModule IEncryptionModule) DecoderCreator

SetupEncryptionModule 安装加密模块

func (DecoderCreator) SetupMACModule

func (dc DecoderCreator) SetupMACModule(macModule IMACModule) DecoderCreator

SetupMACModule 安装MAC模块

func (DecoderCreator) Spawn

func (dc DecoderCreator) Spawn() IDecoder

Spawn 获取消息包解码器

type Encoder

type Encoder struct {
	EncryptionModule  IEncryptionModule  // 加密模块
	MACModule         IMACModule         // MAC模块
	CompressionModule ICompressionModule // 压缩模块
	Encryption        bool               // 开启加密
	PatchMAC          bool               // 开启MAC
	CompressedSize    int                // 启用压缩阀值(字节),<=0表示不开启
}

Encoder 消息包编码器

func (*Encoder) Encode

func (e *Encoder) Encode(flags gtp.Flags, msg gtp.MsgReader) (ret binaryutil.RecycleBytes, err error)

Encode 编码消息包

type EncoderCreator

type EncoderCreator struct {
	// contains filtered or unexported fields
}

EncoderCreator 消息包编码器构建器

func CreateEncoder

func CreateEncoder() EncoderCreator

CreateEncoder 创建消息包编码器

func (EncoderCreator) SetupCompressionModule

func (ec EncoderCreator) SetupCompressionModule(compressionModule ICompressionModule, compressedSize int) EncoderCreator

SetupCompressionModule 安装压缩模块

func (EncoderCreator) SetupEncryptionModule

func (ec EncoderCreator) SetupEncryptionModule(encryptionModule IEncryptionModule) EncoderCreator

SetupEncryptionModule 安装加密模块

func (EncoderCreator) SetupMACModule

func (ec EncoderCreator) SetupMACModule(macModule IMACModule) EncoderCreator

SetupMACModule 安装MAC模块

func (EncoderCreator) Spawn

func (ec EncoderCreator) Spawn() IEncoder

Spawn 获取消息包编码器

type EncryptionModule

type EncryptionModule struct {
	Cipher     method.Cipher  // 对称密码算法
	Padding    method.Padding // 填充方案
	FetchNonce FetchNonce     // 获取nonce值
}

EncryptionModule 加密模块

func (*EncryptionModule) SizeOfAddition

func (m *EncryptionModule) SizeOfAddition(msgLen int) (int, error)

SizeOfAddition 附加数据大小

func (*EncryptionModule) Transforming

func (m *EncryptionModule) Transforming(dst, src []byte) (ret binaryutil.RecycleBytes, err error)

Transforming 变换数据

type FetchNonce

type FetchNonce = generic.PairFunc0[[]byte, error] // 获取nonce值

type ICompressionModule

type ICompressionModule interface {
	// Compress 压缩数据
	Compress(src []byte) (dst binaryutil.RecycleBytes, compressed bool, err error)
	// Uncompress 解压缩数据
	Uncompress(src []byte) (dst binaryutil.RecycleBytes, err error)
}

ICompressionModule 压缩模块接口

func NewCompressionModule

func NewCompressionModule(cs method.CompressionStream) ICompressionModule

NewCompressionModule 创建压缩模块

type IDecoder

type IDecoder interface {
	// Decode 解码消息包
	Decode(data []byte, validate ...IValidate) (gtp.MsgPacket, int, error)
	// GC GC
	GC()
}

IDecoder 消息包解码器接口

type IEncoder

type IEncoder interface {
	// Encode 编码消息包
	Encode(flags gtp.Flags, msg gtp.MsgReader) (binaryutil.RecycleBytes, error)
}

IEncoder 消息包编码器接口

type IEncryptionModule

type IEncryptionModule interface {
	// Transforming 变换数据
	Transforming(dst, src []byte) (binaryutil.RecycleBytes, error)
	// SizeOfAddition 附加数据大小
	SizeOfAddition(msgLen int) (int, error)
}

IEncryptionModule 加密模块接口

func NewEncryptionModule

func NewEncryptionModule(cipher method.Cipher, padding method.Padding, fetchNonce FetchNonce) IEncryptionModule

NewEncryptionModule 创建加密模块

type IMACModule

type IMACModule interface {
	// PatchMAC 补充MAC
	PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)
	// VerifyMAC 验证MAC
	VerifyMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)
	// SizeofMAC MAC大小
	SizeofMAC(msgLen int) int
}

IMACModule MAC模块接口

func NewMAC32Module

func NewMAC32Module(h hash.Hash32, pk []byte) IMACModule

NewMAC32Module 创建MAC32模块

func NewMAC64Module

func NewMAC64Module(h hash.Hash64, pk []byte) IMACModule

NewMAC64Module 创建MAC64模块

func NewMACModule

func NewMACModule(h hash.Hash, pk []byte) IMACModule

NewMACModule 创建MAC模块

type IValidate

type IValidate interface {
	// Validate 验证消息包
	Validate(msgHead gtp.MsgHead, msgBuf []byte) error
}

IValidate 验证消息包接口

type MAC32Module

type MAC32Module struct {
	Hash       hash.Hash32 // hash(32bit)函数
	PrivateKey []byte      // 秘钥
}

MAC32Module MAC32模块

func (*MAC32Module) PatchMAC

func (m *MAC32Module) PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)

PatchMAC 补充MAC

func (*MAC32Module) SizeofMAC

func (m *MAC32Module) SizeofMAC(msgLen int) int

SizeofMAC MAC大小

func (*MAC32Module) VerifyMAC

func (m *MAC32Module) VerifyMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)

VerifyMAC 验证MAC

type MAC64Module

type MAC64Module struct {
	Hash       hash.Hash64 // hash(64bit)函数
	PrivateKey []byte      // 秘钥
}

MAC64Module MAC64模块

func (*MAC64Module) PatchMAC

func (m *MAC64Module) PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)

PatchMAC 补充MAC

func (*MAC64Module) SizeofMAC

func (m *MAC64Module) SizeofMAC(msgLen int) int

SizeofMAC MAC大小

func (*MAC64Module) VerifyMAC

func (m *MAC64Module) VerifyMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)

VerifyMAC 验证MAC

type MACModule

type MACModule struct {
	Hash       hash.Hash // hash函数
	PrivateKey []byte    // 秘钥
}

MACModule MAC模块

func (*MACModule) PatchMAC

func (m *MACModule) PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)

PatchMAC 补充MAC

func (*MACModule) SizeofMAC

func (m *MACModule) SizeofMAC(msgLen int) int

SizeofMAC MAC大小

func (*MACModule) VerifyMAC

func (m *MACModule) VerifyMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst []byte, err error)

VerifyMAC 验证MAC

Jump to

Keyboard shortcuts

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