Documentation
¶
Index ¶
- Constants
- Variables
- type Codec
- type LengthOptions
- type Option
- func WithByteOrder(value binary.ByteOrder) Option[*LengthOptions]
- func WithEncodeLargeMessage(function func(largeMsg []byte, maxLen int) (out []byte, err error)) Option[*LengthOptions]
- func WithLengthSize(value int) Option[*LengthOptions]
- func WithMagic[T Options](magicBytes []byte) Option[T]
- func WithMaxDecodedLength[T Options](maxDecodedLength int) Option[T]
- func WithMaxEncodedLength[T Options](maxEncodedLength int) Option[T]
- func WithMessageCodec[T Options](messageCodec message.Codec) Option[T]
- func WithWarningEncodedLength[T Options](warningEncodedLength int) Option[T]
- type Options
- type OptionsBase
- func (opts *OptionsBase) Complete() error
- func (opts *OptionsBase) GetMagicBytes() []byte
- func (opts *OptionsBase) GetMagicSize() int
- func (opts *OptionsBase) GetMaxDecodedLength() int
- func (opts *OptionsBase) GetMaxEncodedLength() int
- func (opts *OptionsBase) GetMessageCodec() message.Codec
- func (opts *OptionsBase) GetWarningEncodedLength() int
- func (opts *OptionsBase) SetMagicBytes(value []byte)
- func (opts *OptionsBase) SetMaxDecodedLength(value int)
- func (opts *OptionsBase) SetMaxEncodedLength(value int)
- func (opts *OptionsBase) SetMessageCodec(value message.Codec)
- func (opts *OptionsBase) SetWarningEncodedLength(value int)
Constants ¶
View Source
const ( DefaultMaxMessageLength int = 8 * 1024 DefaultWarningEncodedMsgLen int = 4 * 1024 )
Variables ¶
View Source
var ( DefaultLengthByteOrder = binary.LittleEndian DefaultLengthSize = 2 MaxLengthSize = 4 )
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec interface { // Encode // @Description: 消息编码 // @param msg 输入消息 // @return []bytes 编码结果输出 // @return error // Encode(msg any) ([]byte, error) // Decode // @Description: 消息解码 // @param []byte 输入 // @return []Msg 解码消息输出 // @return totalLen 消息所占字节大小 // @return error // Decode(reader gnet.Reader) ([]any, int, error) }
Codec
@Description: 编解码器
func NewLengthFieldCodec ¶
func NewLengthFieldCodec(opts ...Option[*LengthOptions]) (Codec, error)
type LengthOptions ¶
type LengthOptions struct { OptionsBase // 字节序 ByteOrder binary.ByteOrder // 消息长度所占字节数 LengthSize int // 大消息编码函数 EncodeLargeMessage func(largeMsg []byte, maxLen int) (out []byte, err error) }
func (*LengthOptions) Complete ¶
func (opts *LengthOptions) Complete() error
type Option ¶
type Option[T Options] func(o T)
func WithByteOrder ¶
func WithByteOrder(value binary.ByteOrder) Option[*LengthOptions]
func WithEncodeLargeMessage ¶ added in v0.0.4
func WithLengthSize ¶
func WithLengthSize(value int) Option[*LengthOptions]
func WithMaxDecodedLength ¶
func WithMaxEncodedLength ¶
type Options ¶
type Options interface { GetMagicBytes() []byte SetMagicBytes([]byte) GetMagicSize() int GetMaxDecodedLength() int SetMaxDecodedLength(int) GetMaxEncodedLength() int SetMaxEncodedLength(int) GetWarningEncodedLength() int SetWarningEncodedLength(int) GetMessageCodec() message.Codec SetMessageCodec(message.Codec) }
type OptionsBase ¶
type OptionsBase struct {
// contains filtered or unexported fields
}
func (*OptionsBase) Complete ¶
func (opts *OptionsBase) Complete() error
func (*OptionsBase) GetMagicBytes ¶
func (opts *OptionsBase) GetMagicBytes() []byte
func (*OptionsBase) GetMagicSize ¶
func (opts *OptionsBase) GetMagicSize() int
func (*OptionsBase) GetMaxDecodedLength ¶
func (opts *OptionsBase) GetMaxDecodedLength() int
func (*OptionsBase) GetMaxEncodedLength ¶
func (opts *OptionsBase) GetMaxEncodedLength() int
func (*OptionsBase) GetMessageCodec ¶
func (opts *OptionsBase) GetMessageCodec() message.Codec
func (*OptionsBase) GetWarningEncodedLength ¶
func (opts *OptionsBase) GetWarningEncodedLength() int
func (*OptionsBase) SetMagicBytes ¶
func (opts *OptionsBase) SetMagicBytes(value []byte)
func (*OptionsBase) SetMaxDecodedLength ¶
func (opts *OptionsBase) SetMaxDecodedLength(value int)
func (*OptionsBase) SetMaxEncodedLength ¶
func (opts *OptionsBase) SetMaxEncodedLength(value int)
func (*OptionsBase) SetMessageCodec ¶
func (opts *OptionsBase) SetMessageCodec(value message.Codec)
func (*OptionsBase) SetWarningEncodedLength ¶
func (opts *OptionsBase) SetWarningEncodedLength(value int)
Click to show internal directories.
Click to hide internal directories.