engine

package module
v3.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 1 Imported by: 0

README

engine.io-go-parser

Go Reference Go Report Card

Description

A Go implementation of the Engine.IO protocol parser. This package is used by both engine.io-client-go and engine.io for protocol encoding and decoding.

Installation

go get github.com/technance-foundation/socket.io/parsers/engine/v3

Features

  • Packet encoding/decoding
  • Payload encoding/decoding
  • Binary data support
  • Protocol v3 and v4 support
  • UTF-8 encoding support

How to use

Basic Usage
package main

import (
    "bytes"
    "fmt"

    "github.com/technance-foundation/socket.io/parsers/engine/v3/packet"
    "github.com/technance-foundation/socket.io/v3/pkg/types"
)

func main() {
    // Initialize parser
    parser := packet.Parserv4()

    // Encode a packet
    encodedData, err := parser.EncodePacket(&packet.Packet{
        Type: packet.MESSAGE,
        Data: bytes.NewBuffer([]byte("Hello World")),
    }, true)
    if err != nil {
        panic(err)
    }

    // Decode a packet
    decodedPacket, err := parser.DecodePacket(encodedData)
    if err != nil {
        panic(err)
    }

    fmt.Printf("Decoded message: %s\n", decodedPacket.Data)
}
Working with Payloads
func handlePayload() {
    parser := packet.Parserv4()

    packets := []*packet.Packet{
        {
            Type: packet.MESSAGE,
            Data: bytes.NewBuffer([]byte("First message")),
        },
        {
            Type: packet.MESSAGE,
            Data: bytes.NewBuffer([]byte("Second message")),
        },
    }

    // Encode payload
    encoded, err := parser.EncodePayload(packets)
    if err != nil {
        panic(err)
    }

    // Decode payload
    decoded, err := parser.DecodePayload(encoded)
    if err != nil {
        panic(err)
    }
}

API Reference

Parser Interface
EncodePacket
EncodePacket(packet *packet.Packet, supportsBinary bool) (types.BufferInterface, error)
  • packet: The packet to encode
  • supportsBinary: Enable binary support
  • Returns: Encoded packet and error if any
DecodePacket
DecodePacket(data types.BufferInterface) (*packet.Packet, error)
  • data: The data to decode
  • Returns: Decoded packet and error if any
EncodePayload
EncodePayload(packets []*packet.Packet) (types.BufferInterface, error)
  • packets: Array of packets to encode
  • Returns: Encoded payload and error if any
DecodePayload
DecodePayload(data types.BufferInterface) ([]*packet.Packet, error)
  • data: The payload to decode
  • Returns: Array of decoded packets and error if any

Development

Prerequisites
  • Go 1.26.0+
  • Make
Testing

Run the test suite:

make test

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

If you encounter any issues or have questions, please file them in the issues section.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const VERSION = version.VERSION

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
Package packet defines the Engine.IO packet types and structures.
Package packet defines the Engine.IO packet types and structures.
Package parser provides Engine.IO protocol packet encoding and decoding.
Package parser provides Engine.IO protocol packet encoding and decoding.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL