Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnexpectedType = errors.New("Unexpected type")
ErrUnexpectedType is returned when the decoder is trying to replace placeholders with []byte and encounters an unexpected type
var ErrWaitingForMorePackets = errors.New("Waiting for more packets")
ErrWaitingForMorePackets is returned when the Decoder has not yet received enough BinaryPackets to fully decode a binary message
Functions ¶
func HasBinary ¶
func HasBinary(data interface{}) bool
HasBinary returns true if the data contains []byte or fixed-length byte arrays, false otherwise
func IsRootNamespace ¶
IsRootNamespace returns true if the namespace is / or "", false otherwise
Types ¶
type BinaryDecoder ¶
type BinaryDecoder struct {
// contains filtered or unexported fields
}
BinaryDecoder reconstructs BinaryEvents and BinaryAcks from multiple EnginePackets
func (*BinaryDecoder) Decode ¶
func (d *BinaryDecoder) Decode(packet engine.Packet) (Packet, error)
Decode returns either a Message, or ErrWaitingForMorePackets if additional Packets are required to fully reconstruct a BinaryEvent or BinaryAck
func (*BinaryDecoder) Reset ¶
func (d *BinaryDecoder) Reset()
Reset clears the current state of the BinaryDecoder
type BinaryPlaceholder ¶
BinaryPlaceholder represents the position of a particular binary attachement in a string-encoded packet
type Packet ¶
type Packet struct {
// Type is the socket.io defined type of the packet
Type PacketType
// ID is set on outgoing Packets that require an Ack,
// and on incoming packets that Ack the receipt of a Packet.
ID *int64
// Namespace is used to define which sockets will receive the Packet
Namespace string
// AttachmentCount is the number of binary attachments that will be sent
// or received in addition to the main Packet
AttachmentCount int
// Data is the data contained in the packet
Data interface{}
}
Packet is a Socket.IO packet
func (*Packet) Encode ¶
Encode encodes a Packet into a format suitable for transmission using an engine.io transport. It returns a slice of byte slices which contain the socket.io encoded contents of the packet.
The length of the slice returned by Encode is always at least 1, unless an error occurred during encoding. The exact length of the slice returned by Encode is dependant on the value of the Type & Data fields of the packet and the value of the supportsBinary argument. If supportsBinary is false, Encode returns a slice with a single element. If supportsBinary is true, and Type is either BinaryEvent or BinaryAck, Encode returns a slice with 1 + n additional elements, where n is the total number of byte slices and byte arrays present in the Data field, or are present at any level in any struct, array, or slice in the Data field.
The first element is the raw bytes of a string-encoded Socket.IO packet. Additional elements are the raw bytes of a binary-encoded Socket.IO packet.
type PacketType ¶
type PacketType int
PacketType is the Socket.IO-defined type of this packet
const ( // Connect is a packet that is sent when the remote connection is // initially established Connect PacketType = iota // Disconnect is a packet that is sent when the remote connection is broken // either intentionally or unintentionally Disconnect // Event is a packet that contains event information. Packets of this type // may be sent by either side at any time after the connection is established Event // Ack is a packet that contains a payload acknowledging receipt of a previously // sent Event Ack // Error is a packet that contains error information Error // BinaryEvent is a packet that contains event information. Packets of this type // may be sent by either side at any time after the connection is established BinaryEvent // BinaryAck is a packet that contains a payload acknowledging receipt of a previously // sent Event BinaryAck )