Documentation
¶
Index ¶
- Constants
- func MarshalBody(pkt *fatchoy.Packet, threshold int, encryptor cipher.BlockCryptor) ([]byte, error)
- func ReadMagicLenData(r io.Reader) ([]byte, error)
- func ReadPacket(enc Encoder, rd io.Reader, decrypt cipher.BlockCryptor) (*fatchoy.Packet, error)
- func Register(v Encoder)
- func UnmarshalBody(payload []byte, decrypt cipher.BlockCryptor, pkt *fatchoy.Packet) error
- func WriteMagicLenData(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) Command() uint16
- func (h V1Header) Flag() uint8
- func (h V1Header) Len() uint32
- func (h V1Header) MD5Sum() string
- func (h V1Header) MsgID() uint32
- func (h V1Header) Pack(pkt *fatchoy.Packet, size uint16)
- func (h V1Header) Seq() uint16
- func (h V1Header) SetChecksum(payload []byte)
- func (h V1Header) SetFields(pkt *fatchoy.Packet)
- func (h V1Header) Type() uint8
- type V2Header
- func (h V2Header) CalcChecksum(payload []byte) uint32
- func (h V2Header) Checksum() uint32
- func (h V2Header) Command() uint16
- func (h V2Header) Flag() uint8
- 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.Packet, size uint32)
- func (h V2Header) Seq() uint32
- func (h V2Header) SetChecksum(payload []byte)
- func (h V2Header) SetFields(pkt *fatchoy.Packet)
- func (h V2Header) Type() uint8
Constants ¶
View Source
const ( V1EncoderVersion = 3 V1HeaderSize = 16 // 包头大小 V1MaxPayloadBytes = 64 * 1024 // 64K V1CompressThreshold = 4 * 1024 // 压缩阈值(4k) )
View Source
const ( V2EncoderVersion = 1 V2HeaderSize = 24 // 包头大小 V2MaxPayloadBytes = 64 * 1024 * 1024 // 64M V2CompressThreshold = 8 * 1024 // 压缩阈值(8K) )
Variables ¶
This section is empty.
Functions ¶
func MarshalBody ¶ added in v0.4.1
把消息序列化为字节流,有压缩和加密,内部会修改Flags字段
func ReadMagicLenData ¶ added in v0.6.6
读取2字节开头的数据
func ReadPacket ¶ added in v0.4.1
func UnmarshalBody ¶ added in v0.4.1
把字节流反序列化为消息,有解密和解压,内部会修改Flags字段
Types ¶
type Encoder ¶ added in v0.1.12
type Encoder interface {
// name and version
Name() string
Version() int
Clone() Encoder
// 把消息编码到`w`,内部除了flag不应该修改其它字段
Marshal(pkt *fatchoy.Packet, encrypt cipher.BlockCryptor, w io.Writer) (int, error)
// 根据head和body解码消息到
Unmarshal(header, body []byte, decrypt cipher.BlockCryptor, pkt *fatchoy.Packet) error
// 按协议格式读取head和body
ReadHeadBody(r io.Reader) ([]byte, []byte, error)
}
消息编/解码接口
func CreateEncoder ¶ added in v0.3.8
func NewV1Encoder ¶ added in v0.1.12
func NewV2Encoder ¶ added in v0.1.12
Click to show internal directories.
Click to hide internal directories.