parser

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 12 Imported by: 7

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

func IsBinary

func IsBinary(data any) bool

Returns true if obj is a Buffer or a File.

func NewBinaryReconstructor

func NewBinaryReconstructor(packet *Packet) *binaryreconstructor

Types

type Decoder

type Decoder interface {
	events.EventEmitter

	Add(any) error
	Destroy()
}

A socket.io Decoder instance

func NewDecoder

func NewDecoder() Decoder

type Encoder

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

A socket.io Encoder instance

func NewEncoder

func NewEncoder() Encoder

type Packet

type Packet struct {
	Type        PacketType `json:"type" mapstructure:"type" msgpack:"type"`
	Nsp         string     `json:"nsp" mapstructure:"nsp" msgpack:"nsp"`
	Data        any        `json:"data,omitempty" mapstructure:"data,omitempty" msgpack:"data,omitempty"`
	Id          *uint64    `json:"id,omitempty" mapstructure:"id,omitempty" msgpack:"id,omitempty"`
	Attachments *uint64    `json:"attachments,omitempty" mapstructure:"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(data *Packet, buffers []types.BufferInterface) (_ *Packet, err 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 {
	// A socket.io Encoder instance
	NewEncoder() Encoder

	// A socket.io Decoder instance
	NewDecoder() Decoder
}

func NewParser

func NewParser() Parser

type Placeholder

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

Jump to

Keyboard shortcuts

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