websocket

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ImportSpecifier = "@gox/websocket"
	ClientPath      = "/_gox/websocket/client.js"
	HandshakePath   = "/_gox/websocket/handshake"
)
View Source
const (
	FlagInternal byte = 1 << 0
	FlagTransfer byte = 1 << 1
)
View Source
const ProtocolVersion byte = 0x01

Variables

View Source
var ClientSource []byte

ClientSource is the JavaScript module served from ClientPath.

View Source
var ErrMalformedPacket = errors.New("malformed GOX WebSocket packet")

Functions

func ArgumentTypeName

func ArgumentTypeName(argumentType ArgumentType) string

func BindArguments

func BindArguments(arguments []Argument, expected []reflect.Type) ([]any, error)

func BindArgumentsWithTransfers

func BindArgumentsWithTransfers(arguments []Argument, expected []reflect.Type, files map[uint64]gox.File) ([]any, error)

func DecodeBigInt

func DecodeBigInt(data []byte) (*big.Int, error)

DecodeBigInt decodes one canonical BIGINT argument without limiting its precision to uint64.

func DecodeCompactUint

func DecodeCompactUint(data []byte) (uint64, int, error)

DecodeCompactUint decodes one canonical compact uint and returns how many bytes were consumed.

func DecodeFileReference

func DecodeFileReference(data []byte) (uint64, error)

func DecodeFilesReference

func DecodeFilesReference(data []byte) ([]uint64, error)

func EncodeArguments

func EncodeArguments(arguments []Argument) ([]byte, error)

func EncodeBigInt

func EncodeBigInt(value *big.Int) ([]byte, error)

EncodeBigInt creates the canonical decimal payload of one BIGINT argument.

func EncodeCompactUint

func EncodeCompactUint(value uint64) []byte

EncodeCompactUint encodes a uint64 as a width byte followed by the minimum number of big-endian bytes. Zero is encoded as one zero byte.

func EncodeFileReference

func EncodeFileReference(transferID uint64) ([]byte, error)

EncodeFileReference creates the payload of one FILE argument.

func EncodeFilesReference

func EncodeFilesReference(transferIDs []uint64) ([]byte, error)

EncodeFilesReference creates the payload of one FILES argument while preserving the original file order.

func EncodePacket

func EncodePacket(packet Packet) ([]byte, error)

func EncodeValuesWithTransfers

func EncodeValuesWithTransfers(values []any, allocate func() uint64, clients ...gox.ClientIslandRuntime) ([]Argument, []Transfer, error)

EncodeValuesWithTransfers encodes event values and extracts file bodies into independent transfers referenced by FILE and FILES arguments.

func EventName

func EventName(packet Packet) string

func HeaderText

func HeaderText(packet Packet, headerType HeaderType) string

func HeaderUint

func HeaderUint(packet Packet, headerType HeaderType) (uint64, bool)

Types

type Argument

type Argument struct {
	Type ArgumentType
	Data []byte
}

func DecodeArguments

func DecodeArguments(data []byte) ([]Argument, error)

func EncodeValue

func EncodeValue(value any, clients ...gox.ClientIslandRuntime) (Argument, error)

EncodeValue converts one server value into its stable wire category.

func EncodeValues

func EncodeValues(values []any) ([]Argument, error)

type ArgumentType

type ArgumentType byte
const (
	ArgumentNull    ArgumentType = 0x00
	ArgumentText    ArgumentType = 0x01
	ArgumentNumber  ArgumentType = 0x02
	ArgumentBoolean ArgumentType = 0x03
	ArgumentDate    ArgumentType = 0x04
	ArgumentJSON    ArgumentType = 0x05
	ArgumentBinary  ArgumentType = 0x06
	ArgumentFile    ArgumentType = 0x07
	ArgumentFiles   ArgumentType = 0x08
	ArgumentBigInt  ArgumentType = 0x09
	ArgumentHTML    ArgumentType = 0x0a
)

type BindingError

type BindingError struct {
	Code     string
	Argument int
	Received string
	Expected string
	Cause    error
}

func (*BindingError) Error

func (err *BindingError) Error() string

func (*BindingError) Unwrap

func (err *BindingError) Unwrap() error
type Header struct {
	Type  HeaderType
	Value []byte
}

type HeaderType

type HeaderType byte
const (
	HeaderEventName     HeaderType = 0x01
	HeaderRequestID     HeaderType = 0x02
	HeaderTransferID    HeaderType = 0x03
	HeaderSequence      HeaderType = 0x04
	HeaderTotalSize     HeaderType = 0x05
	HeaderFileName      HeaderType = 0x06
	HeaderMIMEType      HeaderType = 0x07
	HeaderErrorCode     HeaderType = 0x08
	HeaderEventID       HeaderType = 0x09
	HeaderChannelID     HeaderType = 0x0a
	HeaderChannelReason HeaderType = 0x0b
)

type Packet

type Packet struct {
	Type      PacketType
	Flags     byte
	Headers   []Header
	Arguments []Argument
	Payload   []byte
}

func DecodePacket

func DecodePacket(data []byte) (Packet, error)

type PacketType

type PacketType byte
const (
	PacketEvent           PacketType = 0x01
	PacketRequest         PacketType = 0x02
	PacketResponse        PacketType = 0x03
	PacketError           PacketType = 0x04
	PacketTransferBegin   PacketType = 0x10
	PacketTransferChunk   PacketType = 0x11
	PacketTransferEnd     PacketType = 0x12
	PacketTransferAbort   PacketType = 0x13
	PacketChannelJoin     PacketType = 0x20
	PacketChannelAccepted PacketType = 0x21
	PacketChannelRejected PacketType = 0x22
	PacketChannelLeave    PacketType = 0x23
	PacketChannelEvent    PacketType = 0x24
	PacketChannelRequest  PacketType = 0x25
	PacketChannelResponse PacketType = 0x26
	PacketChannelError    PacketType = 0x27
)

type Transfer

type Transfer struct {
	ID       uint64
	Name     string
	MIMEType string
	Size     int64
	File     gox.File
}

Jump to

Keyboard shortcuts

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