nano: github.com/lonnng/nano/internal/codec Index | Files

package codec

import "github.com/lonnng/nano/internal/codec"

Index

Package Files

codec.go

Constants

const (
    HeadLength    = 4
    MaxPacketSize = 64 * 1024
)

Codec constants.

Variables

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

ErrPacketSizeExcced is the error used for encode/decode.

func Encode Uses

func 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

type Decoder Uses

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

A Decoder reads and decodes network data slice

func NewDecoder Uses

func NewDecoder() *Decoder

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

func (*Decoder) Decode Uses

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

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

Package codec imports 3 packages (graph). Updated 2019-08-09. Refresh now. Tools for package owners.