https://github.com/zishang520/engine.io-go-parser
engine.io packet parser for golang.
https://github.com/zishang520/engine.io-go-parser
Last synced: about 1 year ago
JSON representation
engine.io packet parser for golang.
- Host: GitHub
- URL: https://github.com/zishang520/engine.io-go-parser
- Owner: zishang520
- License: mit
- Created: 2023-05-30T08:12:20.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-20T06:42:21.000Z (about 1 year ago)
- Last Synced: 2025-03-28T12:11:09.331Z (about 1 year ago)
- Language: Go
- Size: 79.1 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# engine.io-go-parser
[](https://github.com/zishang520/engine.io-go-parser/actions/workflows/go.yml)
[](https://pkg.go.dev/github.com/zishang520/engine.io-go-parser)
This is the golang parser for the engine.io protocol encoding,
shared by both
[engine.io-client-go(not ready)](https://github.com/zishang520/engine.io-client-go) and
[engine.io](https://github.com/zishang520/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:
```go
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](https://github.com/zishang520/engine.io-go-parser/issues)
## Development
To contribute patches, run tests or benchmarks, make sure to clone the
repository:
```bash
git clone git://github.com/zishang520/engine.io-go-parser.git
```
Then:
```bash
cd engine.io-go-parser
make test
```
See the `Tests` section above for how to run tests before submitting any patches.
## License
MIT