Skip to content

Releases

Funbit v1.1.0 - Erlang-style Bitstring Processing Library for Go

Choose a tag to compare

@funvibe funvibe released this 11 Oct 16:58

High-Performance Bitstring Processing Library for Go

A Go library for Erlang-style bitstring construction, pattern matching, and binary data processing. It includes features such as UTF-8 support, endianness control, and protocol parsing.

Features

  • Bitstring Construction: Build binary data with <<value:size/type>> syntax.
  • Pattern Matching: Extract data with flexible pattern matching.
  • UTF-8 Support: Native UTF-8/UTF-16/UTF-32 string handling.
  • Endianness Control: Big-endian, little-endian, and native byte order.
  • Flexible Sizing: Bit-level precision with custom sizes.
  • Signedness Support: Signed and unsigned integer types.
  • High Performance: Optimized for speed and memory efficiency.
  • Protocol Ready: Built-in support for common network protocols.

Installation

go get github.com/funvibe/funbit

Quick Start

package main

import (
    "fmt"
    "github.com/funvibe/funbit/pkg/funbit"
)

func main() {
    // Build bitstring
    data, _ := funbit.Build("<<0xDEAD:16/big, 'Hello'/binary, 0xBEEF:16/big>>")
    fmt.Printf("Built: %v\n", data)
    
    // Pattern matching
    matches, bindings := funbit.Match(data, "<<header:16/big, text/binary, footer:16/big>>")
    if matches {
        fmt.Printf("Header: 0x%X\n", bindings["header"])
        fmt.Printf("Text: %s\n", bindings["text"])
        fmt.Printf("Footer: 0x%X\n", bindings["footer"])
    }
}

Advanced Features

UTF-8 String Processing

// UTF-8 encoding/decoding
data, _ := funbit.Build("<<'Hello 🚀'/utf8>>")
matches, bindings := funbit.Match(data, "<<text/utf8>>")

Network Protocol Parsing

// TCP header parsing
tcpData := []byte{0x1F, 0x90, 0x00, 0x50, 0x00, 0x00, 0x00, 0x01}
matches, bindings := funbit.Match(tcpData, "<<src:16, dst:16, seq:32>>")

Endianness Control

// Big-endian vs little-endian
bigEndian, _ := funbit.Build("<<0x1234:16/big>>")     // [0x12, 0x34]
littleEndian, _ := funbit.Build("<<0x1234:16/little>>") // [0x34, 0x12]

Documentation

  • API Reference: See pkg/funbit/ and examples/ directory for usage patterns.
  • Test Cases: The acceptancetests/ directory contains comprehensive examples.
  • Specification: See doc/BIT_SYNTAX_SPEC.md.

Testing

# Run all tests
go test ./...

# Run acceptance tests
go test ./acceptancetests -v

# Run specific feature tests
go test ./acceptancetests -run "TestBitstringBasic"

Use Cases

  • Network Protocol Parsing: TCP, UDP, HTTP headers
  • Binary File Formats: PNG, JPEG, PDF processing
  • Cryptographic Operations: Hash algorithms, encryption
  • IoT Data Processing: Sensor data, telemetry
  • Game Development: Binary asset formats
  • System Programming: Low-level data manipulation

Contributing

Contributions are accepted.

License

MIT License. See the LICENSE file for details.