codec

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeadLength    = 4
	MaxPacketSize = 64 * 1024
)

Codec constants.

Variables

View Source
var ErrPacketSizeExceed = errors.New("codec: packet size exceed")

ErrPacketSizeExceed is the error used for encode/decode.

Functions

func Encode

func Encode(typ packet.Type, data []byte) ([]byte, error)

Encode 从原始raw bytes创建一个用于网络传输的 packet.Packet 结构,参考网易 pomelo 协议 Protocol refs: https://github.com/NetEase/pomelo/wiki/Communication-Protocol

-<type>-|--------<length>--------|-<data>- --------|------------------------|-------- 1 byte packet type, 3 bytes packet data length(big end), and data segment

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder reads and decodes network data slice

func NewDecoder

func NewDecoder() *Decoder

NewDecoder returns a new decoder that used for decode network bytes slice.

func (*Decoder) Decode

func (c *Decoder) Decode(data []byte) ([]*packet.Packet, error)

Decode decode the network bytes slice to packet.Packet(s) TODO(Warning): shared slice

Jump to

Keyboard shortcuts

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