engineio

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package engineio implements the Engine.IO v4 protocol codec — the transport framing layer that Socket.IO is built on. It encodes and decodes the small set of Engine.IO packets and the polling "payload" that batches several packets into a single HTTP body.

Engine.IO packet wire format (string): a single-digit type prefix followed by the packet data, e.g. "4hello" is a MESSAGE packet carrying "hello".

Index

Constants

View Source
const Protocol = 4

Protocol is the Engine.IO protocol revision implemented here.

Variables

View Source
var ErrEmptyPacket = errors.New("engineio: empty packet")

ErrEmptyPacket is returned when decoding an empty packet string.

Functions

func EncodePayload

func EncodePayload(packets []Packet) string

EncodePayload joins packets into a single polling payload, separated by the record separator.

Types

type Packet

type Packet struct {
	// Type is the Engine.IO packet type (Open, Message, Ping, ...).
	Type PacketType
	// Data is the textual payload for string packets.
	Data string
	// Binary holds raw bytes for binary packets; when non-nil the packet is
	// encoded with a "b" prefix + base64 in polling payloads.
	Binary []byte
}

Packet is a single Engine.IO packet.

func Decode

func Decode(s string) (Packet, error)

Decode parses a single packet from its string wire form.

func DecodePayload

func DecodePayload(payload string) ([]Packet, error)

DecodePayload splits a polling payload into its constituent packets.

func NewMessage

func NewMessage(data string) Packet

NewMessage builds a MESSAGE packet with string data.

func NewOpen

func NewOpen(handshakeJSON string) Packet

NewOpen builds an OPEN packet carrying handshake JSON.

func (Packet) Encode

func (p Packet) Encode() string

Encode renders a packet to its string wire form (used by the websocket transport for text frames). Binary packets return their base64 form here.

type PacketType

type PacketType byte

PacketType identifies an Engine.IO packet.

const (
	// Open is sent by the server on connection with the handshake data.
	Open PacketType = iota
	// Close requests the transport be closed.
	Close
	// Ping is part of the heartbeat (server -> client in EIO4).
	Ping
	// Pong answers a Ping.
	Pong
	// Message carries an application payload (a Socket.IO packet).
	Message
	// Upgrade signals a transport upgrade (polling -> websocket).
	Upgrade
	// Noop does nothing; used to cleanly terminate a polling request.
	Noop
)

func (PacketType) String

func (t PacketType) String() string

String returns the lowercase Engine.IO name of the packet type (e.g. "message", "ping"), or "unknown" for an unrecognized value.

Jump to

Keyboard shortcuts

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