codec

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderSize       = 16               // 包头大小(包含长度)
	PacketBytesLimit = (1 << 24) - 1    // 3字节限制
	MaxPayloadBytes  = 16 * 1024 * 1024 // 16M
)

Variables

View Source
var CompressThreshold = 4096 // 默认压缩阈值,4K

Functions

func MarshalV1 added in v1.3.0

func MarshalV1(w io.Writer, pkt fatchoy.IPacket, encryptor cipher.BlockCryptor) (int, error)

内部不应该修改pkt的body

func ReadLenData added in v1.3.0

func ReadLenData(r io.Reader) ([]byte, error)

read length-prefixed data

func ReadPacket added in v1.3.0

func ReadPacket(r io.Reader, decrypt cipher.BlockCryptor, pkt fatchoy.IPacket) error

读取一个packet

func UnmarshalV1 added in v1.3.0

func UnmarshalV1(header Header, body []byte, decrypt cipher.BlockCryptor, pkt fatchoy.IPacket) error

func WriteLenData added in v1.3.0

func WriteLenData(w io.Writer, data []byte) (int, error)

write length-prefixed data

func WritePacket added in v1.3.0

func WritePacket(w io.Writer, encrypt cipher.BlockCryptor, pkt fatchoy.IPacket) error

写入一个packet

Types

type Header []byte

不包含length

func NewHeader added in v1.3.0

func NewHeader() Header

func ReadV1 added in v1.3.0

func ReadV1(r io.Reader) (Header, []byte, error)

使用从r读取消息到pkt,并按需使用decrypt解密,返回读取长度和错误

func (Header) CalcChecksum

func (h Header) CalcChecksum(payload []byte) uint32

校验码包含head和body

func (Header) Checksum

func (h Header) Checksum() uint32

CRC校验码

func (Header) Command

func (h Header) Command() int32

func (Header) Flag

func (h Header) Flag() uint8

标记位

func (Header) Len

func (h Header) Len() uint32

func (Header) MD5Sum

func (h Header) MD5Sum() string

func (Header) Pack added in v1.1.0

func (h Header) Pack(pkt fatchoy.IPacket, size uint32)

func (Header) Seq

func (h Header) Seq() int16

session内的唯一序号

func (Header) SetChecksum added in v1.3.0

func (h Header) SetChecksum(crc uint32)

func (Header) Type

func (h Header) Type() uint8

标记位

type Version added in v1.1.1

type Version uint8
const (
	VersionV1 Version = 1
)

Jump to

Keyboard shortcuts

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