Documentation ¶
Index ¶
- Variables
- type CompressionModule
- type Decoder
- func (d *Decoder) Decode(validate ...IValidate) (gtp.MsgPacket, error)
- func (d *Decoder) DecodeBuff(buff *bytes.Buffer, validate ...IValidate) (gtp.MsgPacket, error)
- func (d *Decoder) DecodeBytes(data []byte, validate ...IValidate) (gtp.MsgPacket, error)
- func (d *Decoder) GC()
- func (d *Decoder) ReadFrom(r io.Reader) (int64, error)
- func (d *Decoder) Reset()
- func (d *Decoder) Write(p []byte) (int, error)
- type DecoderCreator
- func (dc DecoderCreator) SetupCompressionModule(compressionModule ICompressionModule) DecoderCreator
- func (dc DecoderCreator) SetupEncryptionModule(encryptionModule IEncryptionModule) DecoderCreator
- func (dc DecoderCreator) SetupMACModule(macModule IMACModule) DecoderCreator
- func (dc DecoderCreator) Spawn() IDecoder
- type Encoder
- func (e *Encoder) Encode(flags gtp.Flags, msg gtp.MsgReader) error
- func (e *Encoder) EncodeBuff(buff *bytes.Buffer, flags gtp.Flags, msg gtp.MsgReader) error
- func (e *Encoder) EncodeBytes(flags gtp.Flags, msg gtp.MsgReader) (binaryutil.RecycleBytes, error)
- func (e *Encoder) EncodeWriter(writer io.Writer, flags gtp.Flags, msg gtp.MsgReader) error
- func (e *Encoder) Read(p []byte) (int, error)
- func (e *Encoder) Reset()
- func (e *Encoder) WriteTo(w io.Writer) (int64, error)
- type EncoderCreator
- func (ec EncoderCreator) SetupCompressionModule(compressionModule ICompressionModule, compressedSize int) EncoderCreator
- func (ec EncoderCreator) SetupEncryptionModule(encryptionModule IEncryptionModule) EncoderCreator
- func (ec EncoderCreator) SetupMACModule(macModule IMACModule) EncoderCreator
- func (ec EncoderCreator) Spawn() IEncoder
- type EncryptionModule
- type FetchNonce
- type ICompressionModule
- type IDecoder
- type IEncoder
- type IEncryptionModule
- type IMACModule
- type IValidate
- type MAC32Module
- type MAC64Module
- type MACModule
Constants ¶
This section is empty.
Variables ¶
var (
ErrDataNotEnough = io.ErrShortBuffer // 数据不足
)
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) DecodeBuff ¶
DecodeBuff 从指定buff,解码消息包
func (*Decoder) DecodeBytes ¶
DecodeBytes 从指定bytes,解码消息包
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模块
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) EncodeBuff ¶
EncodeBuff 编码消息包,写入指定buffer
func (*Encoder) EncodeBytes ¶
func (e *Encoder) EncodeBytes(flags gtp.Flags, msg gtp.MsgReader) (binaryutil.RecycleBytes, error)
EncodeBytes 编码消息包,返回可回收bytes
func (*Encoder) EncodeWriter ¶
EncodeWriter 编码消息包,写入指定writer
type EncoderCreator ¶
type EncoderCreator struct {
// contains filtered or unexported fields
}
EncoderCreator 消息包编码器构建器
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模块
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 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 { io.Writer io.ReaderFrom // Reset 重置缓存 Reset() // Decode 从缓存,解码消息包 Decode(validate ...IValidate) (gtp.MsgPacket, error) // DecodeBuff 从指定buff,解码消息包 DecodeBuff(buff *bytes.Buffer, validate ...IValidate) (gtp.MsgPacket, error) // DecodeBytes 从指定bytes,解码消息包 DecodeBytes(data []byte, validate ...IValidate) (gtp.MsgPacket, error) // GC GC GC() }
IDecoder 消息包解码器接口
type IEncoder ¶
type IEncoder interface { io.Reader io.WriterTo // Reset 重置缓存 Reset() // Encode 编码消息包,写入缓存 Encode(flags gtp.Flags, msg gtp.MsgReader) error // EncodeWriter 编码消息包,写入指定writer EncodeWriter(writer io.Writer, flags gtp.Flags, msg gtp.MsgReader) error // EncodeBuff 编码消息包,写入指定buffer EncodeBuff(buff *bytes.Buffer, flags gtp.Flags, msg gtp.MsgReader) error // EncodeBytes 编码消息包,返回可回收bytes EncodeBytes(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模块
type MAC32Module ¶
MAC32Module MAC32模块
func (*MAC32Module) PatchMAC ¶
func (m *MAC32Module) PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)
PatchMAC 补充MAC
type MAC64Module ¶
MAC64Module MAC64模块
func (*MAC64Module) PatchMAC ¶
func (m *MAC64Module) PatchMAC(msgId gtp.MsgId, flags gtp.Flags, msgBuf []byte) (dst binaryutil.RecycleBytes, err error)
PatchMAC 补充MAC