codec

package
v0.0.0-...-4e7898a Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

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

Codec constants.

Variables

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

ErrPacketSizeExcced 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 PacketDecoder

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

PacketDecoder interface

type PacketEncoder

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

PacketEncoder interface

type PomeloPacketDecoder

type PomeloPacketDecoder struct{}

PomeloPacketDecoder reads and decodes network data slice following pomelo's protocol

func NewPomeloPacketDecoder

func NewPomeloPacketDecoder() *PomeloPacketDecoder

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

func (*PomeloPacketDecoder) Decode

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

Decode decode the network bytes slice to packet.Packet(s)

func (*PomeloPacketDecoder) DecodeProto

func (c *PomeloPacketDecoder) DecodeProto(data []byte) ([]*pbProto.Packet, error)

Decode decode the network bytes slice to packet.Packet(s)

type PomeloPacketEncoder

type PomeloPacketEncoder struct {
}

PomeloPacketEncoder struct

func NewPomeloPacketEncoder

func NewPomeloPacketEncoder() *PomeloPacketEncoder

NewPomeloPacketEncoder ctor

func (*PomeloPacketEncoder) Encode

func (e *PomeloPacketEncoder) 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

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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