pomeloPacket

package
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 5 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 Encode

func Encode(typ byte, 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

func IntToBytes

func IntToBytes(n int) []byte

IntToBytes Encode packet data length to bytes(Big end)

func InvalidType

func InvalidType(t Type) bool

func ParseHeader

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

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

func TypeName

func TypeName(t Type) string

Types

type Packet

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

func Decode

func Decode(data []byte) ([]*Packet, error)

func Read

func Read(conn net.Conn) ([]*Packet, bool, error)

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 Type

type Type = byte // packet type
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
)

Jump to

Keyboard shortcuts

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