codec

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeadLength    = 4
	MaxPacketSize = 1 << 24 //16MB
)

Codec constants.

Variables

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

ErrPacketSizeExceed is the error used for encode/decode.

Functions

func BytesToInt

func BytesToInt(b []byte) int

BytesToInt decode packet data length byte to int(Big end)

func IntToBytes

func IntToBytes(n int) []byte

IntToBytes encode packet data length to bytes(Big end)

func ParseHeader

func ParseHeader(header []byte) (int, packet.Type, error)

ParseHeader parses a packet header and returns its dataLen and packetType or an error

Types

type Decoder

type Decoder interface {
	Decode(data []byte) ([]*packet.Packet, error)
}

type Encoder

type Encoder interface {
	Encode(typ packet.Type, data []byte) ([]byte, error)
}

type PomeloDecoder

type PomeloDecoder struct {
}

func NewPomeloDecoder

func NewPomeloDecoder() *PomeloDecoder

func (*PomeloDecoder) Decode

func (pd *PomeloDecoder) Decode(data []byte) ([]*packet.Packet, error)

type PomeloEncoder

type PomeloEncoder struct {
}

PomeloEncoder struct

func NewPomeloEncoder

func NewPomeloEncoder() *PomeloEncoder

NewPomeloEncoder ctor

func (*PomeloEncoder) Encode

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

Encode create a packet.Packet from the raw bytes slice and then encode to network bytes slice 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

Jump to

Keyboard shortcuts

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