codec

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: LGPL-2.1 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyBuffer      = errors.New("i/o empty buffer")   // 缓存空
	ErrMsgNotRegistered = errors.New("msg not registered") // 消息未注册
)

BytesPool 字节对象池,用于减少GC提高编解码性能

View Source
var (
	ErrIncorrectMAC = errors.New("incorrect MAC")
)

Functions

This section is empty.

Types

type CompressionModule

type CompressionModule struct {
	CompressionStream method.CompressionStream // 压缩流
	// contains filtered or unexported fields
}

CompressionModule 压缩模块

func (*CompressionModule) Compress

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

Compress 压缩数据

func (*CompressionModule) GC

func (m *CompressionModule) GC()

GC GC

func (*CompressionModule) Uncompress

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

Uncompress 解压缩数据

type Decoder

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

Decoder 消息包解码器

func (*Decoder) Fetch

func (d *Decoder) Fetch() (transport.MsgPacket, error)

Fetch 取出消息包

func (*Decoder) FetchFrom

func (d *Decoder) FetchFrom(buff *bytes.Buffer) (transport.MsgPacket, error)

FetchFrom 取出消息包

func (*Decoder) GC

func (d *Decoder) GC()

GC GC

func (*Decoder) GetCompressionModule

func (d *Decoder) GetCompressionModule() ICompressionModule

GetCompressionModule 获取压缩模块

func (*Decoder) GetEncryptionModule

func (d *Decoder) GetEncryptionModule() IEncryptionModule

GetEncryptionModule 获取加密模块

func (*Decoder) GetMACModule

func (d *Decoder) GetMACModule() IMACModule

GetMACModule 获取MAC模块

func (*Decoder) GetMsgCreator

func (d *Decoder) GetMsgCreator() IMsgCreator

GetMsgCreator 获取消息对象构建器

func (*Decoder) ReadFrom

func (d *Decoder) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom

func (*Decoder) Reset

func (d *Decoder) Reset()

Reset 重置缓存

func (*Decoder) Write

func (d *Decoder) Write(p []byte) (int, error)

Write implements io.Writer

type Encoder

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

Encoder 消息包编码器

func (*Encoder) GetCompressedSize

func (e *Encoder) GetCompressedSize() int

GetCompressedSize 获取启用压缩阀值(字节),<=0表示不开启

func (*Encoder) GetCompressionModule

func (e *Encoder) GetCompressionModule() ICompressionModule

GetCompressionModule 获取压缩模块

func (*Encoder) GetEncryption

func (e *Encoder) GetEncryption() bool

GetEncryption 获取开启加密

func (*Encoder) GetEncryptionModule

func (e *Encoder) GetEncryptionModule() IEncryptionModule

GetEncryptionModule 获取加密模块

func (*Encoder) GetMACModule

func (e *Encoder) GetMACModule() IMACModule

GetMACModule 获取MAC模块

func (*Encoder) GetPatchMAC

func (e *Encoder) GetPatchMAC() bool

GetPatchMAC 获取开启MAC

func (*Encoder) Read

func (e *Encoder) Read(p []byte) (int, error)

Read implements io.Reader

func (*Encoder) Reset

func (e *Encoder) Reset()

Reset 重置缓存

func (*Encoder) Stuff

func (e *Encoder) Stuff(flags transport.Flags, msg transport.Msg) error

Stuff 填充消息

func (*Encoder) StuffTo

func (e *Encoder) StuffTo(writer io.Writer, flags transport.Flags, msg transport.Msg) error

StuffTo 填充消息

func (*Encoder) WriteTo

func (e *Encoder) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo

type EncryptionModule

type EncryptionModule struct {
	CipherStream method.CipherStream // 密码流
	Padding      method.Padding      // 填充方案
	FetchNonce   FetchNonce          // 获取nonce值
	// contains filtered or unexported fields
}

EncryptionModule 加密模块

func (*EncryptionModule) GC

func (m *EncryptionModule) GC()

GC GC

func (*EncryptionModule) SizeOfAddition

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

SizeOfAddition 附加数据大小

func (*EncryptionModule) Transforming

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

Transforming 变换数据

type FetchNonce

type FetchNonce = func() ([]byte, error)

type ICompressionModule

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

ICompressionModule 压缩模块接口

type IDecoder

type IDecoder interface {
	io.Writer
	io.ReaderFrom
	// Reset 重置缓存
	Reset()
	// Fetch 取出消息包
	Fetch() (transport.MsgPacket, error)
	// FetchFrom 取出消息包
	FetchFrom(buff *bytes.Buffer) (transport.MsgPacket, error)
	// GetMsgCreator 获取消息对象构建器
	GetMsgCreator() IMsgCreator
	// GetEncryptionModule 获取加密模块
	GetEncryptionModule() IEncryptionModule
	// GetMACModule 获取MAC模块
	GetMACModule() IMACModule
	// GetCompressionModule 获取压缩模块
	GetCompressionModule() ICompressionModule
	// GC GC
	GC()
}

IDecoder 消息包解码器接口

type IEncoder

type IEncoder interface {
	io.Reader
	io.WriterTo
	// Reset 重置缓存
	Reset()
	// Stuff 填充消息
	Stuff(flags transport.Flags, msg transport.Msg) error
	// StuffTo 填充消息
	StuffTo(writer io.Writer, flags transport.Flags, msg transport.Msg) error
	// GetEncryptionModule 获取加密模块
	GetEncryptionModule() IEncryptionModule
	// GetMACModule 获取MAC模块
	GetMACModule() IMACModule
	// GetCompressionModule 获取压缩模块
	GetCompressionModule() ICompressionModule
	// GetEncryption 获取开启加密
	GetEncryption() bool
	// GetPatchMAC 获取开启MAC
	GetPatchMAC() bool
	// GetCompressedSize 获取启用压缩阀值(字节),<=0表示不开启
	GetCompressedSize() int
}

IEncoder 消息包编码器接口

type IEncryptionModule

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

IEncryptionModule 加密模块接口

type IMACModule

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

IMACModule MAC模块接口

type IMsgCreator

type IMsgCreator interface {
	// Spawn 构建消息
	Spawn(msgId transport.MsgId) (transport.Msg, error)
}

IMsgCreator 消息对象构建器接口

func DefaultMsgCreator

func DefaultMsgCreator() IMsgCreator

DefaultMsgCreator 默认消息对象构建器

type MAC32Module

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

MAC32Module MAC32模块

func (*MAC32Module) GC

func (m *MAC32Module) GC()

GC GC

func (*MAC32Module) PatchMAC

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

PatchMAC 补充MAC

func (*MAC32Module) SizeofMAC

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

SizeofMAC MAC大小

func (*MAC32Module) VerifyMAC

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

VerifyMAC 验证MAC

type MAC64Module

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

MAC64Module MAC64模块

func (*MAC64Module) GC

func (m *MAC64Module) GC()

GC GC

func (*MAC64Module) PatchMAC

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

PatchMAC 补充MAC

func (*MAC64Module) SizeofMAC

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

SizeofMAC MAC大小

func (*MAC64Module) VerifyMAC

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

VerifyMAC 验证MAC

type MACModule

type MACModule struct {
	Hash       hash.Hash // hash函数
	PrivateKey []byte    // 秘钥
	// contains filtered or unexported fields
}

MACModule MAC模块

func (*MACModule) GC

func (m *MACModule) GC()

GC GC

func (*MACModule) PatchMAC

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

PatchMAC 补充MAC

func (*MACModule) SizeofMAC

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

SizeofMAC MAC大小

func (*MACModule) VerifyMAC

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

VerifyMAC 验证MAC

type MsgCreator

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

MsgCreator 消息对象构建器

func (*MsgCreator) Deregister

func (c *MsgCreator) Deregister(msgId transport.MsgId)

Deregister 取消注册消息

func (*MsgCreator) Register

func (c *MsgCreator) Register(msg transport.Msg)

Register 注册消息

func (*MsgCreator) Spawn

func (c *MsgCreator) Spawn(msgId transport.MsgId) (transport.Msg, error)

Spawn 构建消息

Jump to

Keyboard shortcuts

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