Documentation
¶
Overview ¶
Package eioparser implements the Engine.IO packet and payload codecs for both revisions of the protocol that are in use today:
- revision 3, spoken by Engine.IO v3 clients (Socket.IO v2)
- revision 4, spoken by Engine.IO v4+ clients (Socket.IO v3 and above)
It only depends on the Go standard library.
Index ¶
Constants ¶
const ( ProtocolV3 = 3 ProtocolV4 = 4 )
Protocol revisions understood by this package.
const ( ContentTypeText = "text/plain; charset=UTF-8" ContentTypeBinary = "application/octet-stream" )
Content types used by the HTTP long-polling transport.
Variables ¶
var ErrParser = errors.New("engine.io: parser error")
ErrParser is reported when a peer sends something that is not a valid Engine.IO packet or payload.
Functions ¶
func EncodePacket ¶
EncodePacket serialises a single packet the way it is written to a WebSocket frame.
The returned isBinaryFrame reports whether the bytes must be sent as a binary WebSocket frame rather than a text one. When supportsBinary is false binary payloads are base64 encoded into a text frame instead.
Types ¶
type Packet ¶
Packet is a single Engine.IO packet.
Data holds the payload. When Binary is true the payload is an opaque byte string, otherwise it is UTF-8 text. Only Message packets may be binary.
func DecodePacket ¶
DecodePacket parses a single packet as received on a WebSocket frame.
type Payload ¶
type Payload struct {
// Protocol is ProtocolV3 or ProtocolV4.
Protocol int
// SupportsBinary reports whether the peer can handle raw binary bodies.
// It is always false for revision 4, which base64 encodes instead.
SupportsBinary bool
}
Payload encodes and decodes the batches of packets exchanged over HTTP long-polling.
The two protocol revisions use completely different framings:
v3 text: <length-in-utf16-code-units>:<packet>... v3 binary: <0|1><length digits as bytes><0xff><packet>... v4: <packet>\x1e<packet>...