This is the golang parser for the engine.io protocol encoding, shared by both engine.io-client-go(not ready) and engine.io.
The parser can encode/decode packets, payloads, and payloads as binary
with the following methods: Parser.EncodePacket
, Parser.DecodePacket
, Parser.EncodePayload
,
Parser.DecodePayload
.
Example:
import (
"bytes"
"io"
"strings"
"github.com/zishang520/engine.io-go-parser/packet"
"github.com/zishang520/engine.io-go-parser/types"
)
func main() {
p := &packet.Parserv4()
data, _ := p.EncodePacket(&packet.Packet{
Type: packet.MESSAGE,
Data: bytes.NewBuffer([]byte{1, 2, 3, 4}),
Options: nil,
}, true)
decodedData, _ := p.DecodePacket(data)
}
-
EncodePacket
- Encodes a packet.
- Parameters
*packet.Packet
: the packet to encode.bool
: binary support.bool
: utf8 encode, v3 only.
-
DecodePacket
- Parameters
types.BufferInterface
: the packet to decode.bool
: utf8 encode, v3 only.
- Parameters
-
EncodePayload
- Encodes multiple messages (payload).
- If any contents are binary, they will be encoded as base64 strings. Base64 encoded strings are marked with a b before the length specifier
- Parameters
[]*packet.Packet
: an array of packetsbool
: binary support, v3 only.
-
DecodePayload
- Decodes data when a payload is maybe expected. Possible binary contents are decoded from their base64 representation.
- Parameters
types.BufferInterface
: the payload
Standalone tests can be run with make test
which will run the golang tests.
You can run the tests locally using the following command:
make test
To contribute patches, run tests or benchmarks, make sure to clone the repository:
git clone git://github.com/zishang520/engine.io-go-parser.git
Then:
cd engine.io-go-parser
make test
See the Tests
section above for how to run tests before submitting any patches.
MIT