packet

package
v3.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package packet defines the Engine.IO packet types and structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Compress indicates whether the packet should be compressed.
	Compress *bool `json:"compress,omitempty" msgpack:"compress,omitempty"`
	// WsPreEncodedFrame contains a pre-encoded WebSocket frame.
	WsPreEncodedFrame types.BufferInterface `json:"wsPreEncodedFrame,omitempty" msgpack:"wsPreEncodedFrame,omitempty"`
}

Options contains optional packet configuration.

func NewOptions

func NewOptions(compress bool) *Options

NewOptions creates a new Options with the given compress flag.

type Packet

type Packet struct {
	// Type is the packet type (OPEN, CLOSE, PING, PONG, MESSAGE, UPGRADE, NOOP, ERROR).
	Type Type `json:"type" msgpack:"type"`
	// Data contains the packet payload.
	Data io.Reader `json:"data,omitempty" msgpack:"data,omitempty"`
	// Options contains optional packet configuration.
	Options *Options `json:"options,omitempty" msgpack:"options,omitempty"`
}

Packet represents an Engine.IO packet.

func New

func New(packetType Type, data io.Reader) *Packet

New creates a new packet with the given type and data.

func NewWithOptions

func NewWithOptions(packetType Type, data io.Reader, options *Options) *Packet

NewWithOptions creates a new packet with the given type, data, and options.

type Type

type Type string

Type represents the Engine.IO packet type.

const (
	// OPEN is sent from the server when a new transport is opened.
	OPEN Type = "open"
	// CLOSE is sent to request the close of this transport.
	CLOSE Type = "close"
	// PING is sent by the client for keep-alive (heartbeat).
	PING Type = "ping"
	// PONG is sent by the server in response to a PING.
	PONG Type = "pong"
	// MESSAGE is used for actual message transport.
	MESSAGE Type = "message"
	// UPGRADE is sent before upgrading the transport.
	UPGRADE Type = "upgrade"
	// NOOP is used as a no-operation packet.
	NOOP Type = "noop"
	// ERROR indicates a parsing or other error.
	ERROR Type = "error"
)

Packet types for Engine.IO protocol.

func (Type) IsValid

func (t Type) IsValid() bool

IsValid checks if the packet type is a valid Engine.IO packet type.

func (Type) String

func (t Type) String() string

String returns the string representation of the packet type.

Jump to

Keyboard shortcuts

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