Documentation ¶
Index ¶
- Constants
- func ReadLenData(r io.Reader) ([]byte, error)
- func Register(v Encoder)
- func WriteLenData(w io.Writer, data []byte) (int, error)
- type Encoder
- type V1Header
- func (h V1Header) CalcChecksum(payload []byte) uint32
- func (h V1Header) Checksum() uint32
- func (h V1Header) Cmd() int32
- func (h V1Header) Flag() uint16
- func (h V1Header) Len() uint16
- func (h V1Header) MD5Sum() string
- func (h V1Header) MsgID() uint32
- func (h V1Header) Pack(pkt fatchoy.IPacket, size uint16)
- func (h V1Header) Seq() uint16
- func (h V1Header) SetChecksum(payload []byte)
- type V2Header
- func (h V2Header) CalcChecksum(payload []byte) uint32
- func (h V2Header) Checksum() uint32
- func (h V2Header) Cmd() int32
- func (h V2Header) Flag() uint16
- func (h V2Header) Len() uint32
- func (h V2Header) MD5Sum() string
- func (h V2Header) MsgID() uint32
- func (h V2Header) Node() fatchoy.NodeID
- func (h V2Header) Pack(pkt fatchoy.IPacket, size uint32)
- func (h V2Header) Seq() uint16
- func (h V2Header) SetChecksum(payload []byte)
Constants ¶
View Source
const ( V1EncoderVersion = 1 V1HeaderSize = 18 // 包头大小 V1MaxPayloadBytes = 0xFFFF // 64K V1CompressThreshold = 0x1000 // 压缩阈值(4k) )
View Source
const ( V2EncoderVersion = 1 V2HeaderSize = 24 // 包头大小 V2MaxPayloadBytes = 0x4000000 // 64M V2MaxReferCount = 1000 // V2CompressThreshold = 0x2000 // 压缩阈值(8K) )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Encoder ¶ added in v0.1.12
type Encoder interface { Name() string Version() int // 把`pkt`编码到`w`,内部除了flag不应该修改pkt的其它字段 WritePacket(w io.Writer, encrypt cipher.BlockCryptor, pkt fatchoy.IPacket) (int, error) // 按协议格式读取head和body ReadHeadBody(r io.Reader) ([]byte, []byte, error) // 根据head和body解码消息到`pkt` UnmarshalPacket(header, body []byte, decrypt cipher.BlockCryptor, pkt fatchoy.IPacket) error // 从`r`里读取消息到`pkt` ReadPacket(r io.Reader, decrypt cipher.BlockCryptor, pkt fatchoy.IPacket) error }
消息编/解码接口
func GetEncoder ¶ added in v0.1.12
func NewV1Encoder ¶ added in v0.1.12
func NewV2Encoder ¶ added in v0.1.12
Click to show internal directories.
Click to hide internal directories.