Skip to content

zishang520/engine.io-go-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

engine.io-go-parser

Build Status GoDoc

This is the golang parser for the engine.io protocol encoding, shared by both engine.io-client-go(not ready) and engine.io.

How to use

Standalone

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)
}

API

Parser interface

  • 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.
  • 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 packets
      • bool: 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

Tests

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

Support

issues

Development

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.

License

MIT

About

engine.io packet parser for golang.

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages