parser

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolVersion = 4

Variables

This section is empty.

Functions

func EncodePayloads

func EncodePayloads(w io.Writer, packets ...*Packet) error

packets must not be nil.

Note: Writer should either implement io.ByteWriter or it should not have a problem with writing 1 byte at a time.

func EncodedPayloadsLen

func EncodedPayloadsLen(packets ...*Packet) int

`packets` must not be nil.

Types

type HandshakeResponse

type HandshakeResponse struct {
	SID          string   `json:"sid"`
	Upgrades     []string `json:"upgrades"`
	PingInterval int64    `json:"pingInterval"`
	PingTimeout  int64    `json:"pingTimeout"`
	MaxPayload   int64    `json:"maxPayload"`
}

func ParseHandshakeResponse

func ParseHandshakeResponse(p *Packet) (*HandshakeResponse, error)

func (*HandshakeResponse) GetPingInterval

func (hr *HandshakeResponse) GetPingInterval() time.Duration

func (*HandshakeResponse) GetPingTimeout

func (hr *HandshakeResponse) GetPingTimeout() time.Duration

type Packet

type Packet struct {
	IsBinary bool
	Type     PacketType
	Data     []byte
}

func Decode

func Decode(r io.Reader, binaryFrame bool) (*Packet, error)

func DecodePayloads

func DecodePayloads(r io.Reader) ([]*Packet, error)

func DecodeWithLen

func DecodeWithLen(r io.Reader, binaryFrame bool, len int) (*Packet, error)

func NewPacket

func NewPacket(packetType PacketType, isBinary bool, data []byte) (*Packet, error)

func (*Packet) Encode

func (p *Packet) Encode(w io.Writer, supportsBinary bool) error

Note: Writer should either implement io.ByteWriter or should not have a problem with writing 1 byte at a time.

func (*Packet) EncodedLen

func (p *Packet) EncodedLen(supportsBinary bool) int

func (*Packet) String

func (p *Packet) String() string

type PacketType

type PacketType byte
const (
	PacketTypeOpen PacketType = iota
	PacketTypeClose
	PacketTypePing
	PacketTypePong
	PacketTypeMessage
	PacketTypeUpgrade
	PacketTypeNoop
)

func (*PacketType) FromChar

func (p *PacketType) FromChar(b byte) error

func (PacketType) ToChar

func (p PacketType) ToChar() byte

Jump to

Keyboard shortcuts

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