erlgo

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

erlgo

A lightweight Go library that implements the Erlang port protocol for communication between Go and Erlang/OTP applications.

Features

  • Implements standard Erlang port protocol (4-byte length prefix)
  • Clean, simple API for reading and writing messages
  • Zero dependencies beyond Go standard library
  • Designed for efficiency with buffered reading

Installation

go get github.com/mochams/erlgo@latest

Usage

package main

import (
    "log"
    "github.com/mochams/erlgo"
)

func main() {
    // Read a message from Erlang
    messageBytes, err := erlgo.Receive()
    if err != nil {
        log.Fatal(err)
    }
    
    // Process your message bytes here...
    
    // Write a response back to Erlang
    response := []byte("your response data")
    if err := erlgo.Send(response); err != nil {
        log.Fatal(err)
    }
}

API

Receive
func Receive() ([]byte, error)

Reads a length-prefixed message from Erlang through stdin. Returns the message bytes and any error encountered.

Send
func Send(messageBytes []byte) error

Writes a length-prefixed message to Erlang through stdout. Takes the message bytes and returns any error encountered.

Erlang Port Protocol

The library implements the standard Erlang port protocol where each message is prefixed with a 4-byte length in big-endian order, followed by the actual message content.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

Inspired by the needs of the Erlang/OTP community for reliable Go port communication.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Receive added in v0.5.0

func Receive() ([]byte, error)

Receive reads a message from Erlang via stdin. The message follows the Erlang port protocol format: - 4-byte length prefix in big-endian order - followed by the actual message content

The function returns the message content as a byte slice and any error encountered during reading. Possible errors include: - EOF if the port is closed - I/O errors from reading stdin - Message length exceeding available memory

Example:

messageBytes, err := erlgo.Receive()
if err != nil {
    log.Fatal(err)
}
// Process messageBytes...

func Send added in v0.5.0

func Send(messageBytes []byte) error

Send writes a message to Erlang via stdout following the port protocol. The message is automatically prefixed with its length as a 4-byte integer in big-endian order.

Parameters: - messageBytes: The content to be sent to Erlang

Returns an error if the write operation fails. Possible errors include: - I/O errors from writing to stdout - System errors if stdout is closed

Example:

message := []byte("hello")
err := erlgo.Send(message)
if err != nil {
    log.Fatal(err)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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