parser

package
v2.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2025 License: MIT Imports: 11 Imported by: 8 modules, 13 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const Protocol = 5

Protocol version.

Variables

View Source
var (

	// These strings must not be used as event names, as they have a special meaning.
	RESERVED_EVENTS = types.NewSet(
		"connect",
		"connect_error",
		"disconnect",
		"disconnecting",
	)
)

Functions

func HasBinary

func HasBinary(data any) bool

HasBinary checks recursively if the data contains any binary data.

func IsBinary

func IsBinary(data any) bool

IsBinary returns true if the data is a binary type (Buffer or File).

Types

type Decoder

type Decoder interface {
	events.EventEmitter

	Add(any) error
	Destroy()
}

Decoder defines an interface for socket.io decoding.

func NewDecoder

func NewDecoder() Decoder

type Encoder

type Encoder interface {
	Encode(*Packet) []types.BufferInterface
}

Encoder defines an interface for socket.io encoding.

func NewEncoder

func NewEncoder() Encoder

type Packet

type Packet struct {
	Type        PacketType `json:"type" msgpack:"type"`
	Nsp         string     `json:"nsp" msgpack:"nsp"`
	Data        any        `json:"data,omitempty" msgpack:"data,omitempty"`
	Id          *uint64    `json:"id,omitempty" msgpack:"id,omitempty"`
	Attachments *uint64    `json:"attachments,omitempty" msgpack:"attachments,omitempty"`
}

func DeconstructPacket

func DeconstructPacket(packet *Packet) (pack *Packet, buffers []types.BufferInterface)

Replaces every io.Reader | []byte in packet with a numbered placeholder.

func ReconstructPacket

func ReconstructPacket(packet *Packet, buffers []types.BufferInterface) (*Packet, error)

Reconstructs a binary packet from its placeholder packet and buffers

type PacketType

type PacketType byte
const (
	CONNECT       PacketType = '0'
	DISCONNECT    PacketType = '1'
	EVENT         PacketType = '2'
	ACK           PacketType = '3'
	CONNECT_ERROR PacketType = '4'
	BINARY_EVENT  PacketType = '5'
	BINARY_ACK    PacketType = '6'
)

func (PacketType) String

func (t PacketType) String() string

func (PacketType) Valid

func (t PacketType) Valid() bool

type Parser

type Parser interface {
	NewEncoder() Encoder
	NewDecoder() Decoder
}

Parser defines an interface for creating Encoder and Decoder instances.

func NewParser

func NewParser() Parser

NewParser creates a new Parser instance.

type Placeholder

type Placeholder struct {
	Placeholder bool  `json:"_placeholder" msgpack:"_placeholder"`
	Num         int64 `json:"num" msgpack:"num"`
}

Jump to

Keyboard shortcuts

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