cherryPacket

package
v1.1.18 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HeadLength    = 4       // 4 bytes
	MaxPacketSize = 1 << 24 // 16mb

)

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 InvalidType

func InvalidType(t Type) bool

func TypeName

func TypeName(t Type) string

Types

type Packet

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

func (*Packet) Data

func (p *Packet) Data() []byte

func (*Packet) Len

func (p *Packet) Len() int

func (*Packet) SetData

func (p *Packet) SetData(data []byte)

func (*Packet) String

func (p *Packet) String() string

String represents the Packet's in text mode.

func (*Packet) Type

func (p *Packet) Type() Type

type PomeloCodec

type PomeloCodec struct {
}

func NewPomeloCodec

func NewPomeloCodec() *PomeloCodec

func (*PomeloCodec) PacketDecode

func (p *PomeloCodec) PacketDecode(data []byte) ([]cherryFacade.IPacket, error)

func (*PomeloCodec) PacketEncode

func (p *PomeloCodec) PacketEncode(typ byte, data []byte) ([]byte, error)

PacketEncode 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 Type

type Type = byte
const (
	None         Type = 0x00 // None
	Handshake    Type = 0x01 // Handshake represents a handshake: request(client) <====> handshake response(server)
	HandshakeAck Type = 0x02 // HandshakeAck represents a handshake ack from client to server
	Heartbeat    Type = 0x03 // Heartbeat represents a heartbeat
	Data         Type = 0x04 // settings represents a common data packet
	Kick         Type = 0x05 // Kick represents a kick off packet
)

func ParseHeader

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

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

Jump to

Keyboard shortcuts

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