rq_go

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: MIT Imports: 6 Imported by: 2

README

RaptorQ Go Bindings

This repository contains Go bindings for the RaptorQ erasure coding library. It is automatically synchronized from the rq-library repository.

Repository Structure

rq-go/
├── README.md                 # This file
├── go.mod                    # Root Go module file
├── README.md                 # Documentation for Go bindings
├── raptorq.go                # Main Go binding code
└── raptorq_test.go           # Tests for the Go bindings
└── lib/                      # Platform-specific libraries
    ├── README.md             # Documentation for the libraries
    ├── darwin/               # macOS libraries
    │   ├── amd64/            # Intel macOS
    │   │   └── librq_library.a
    │   └── arm64/            # Apple Silicon
    │       └── librq_library.a
    ├── linux/                # Linux libraries
    │   ├── amd64/            # amd64
    │   │   └── librq_library.a
    │   └── arm64/            # ARM64
    │       └── librq_library.a
    └── windows/              # Windows libraries
        └── amd64/            # amd64
            └── librq_library.a

Platform Subfolders

The platform subfolder structure follows Go's standard naming convention:

  • darwin/amd64 - macOS on Intel
  • darwin/arm64 - macOS on Apple Silicon
  • linux/amd64 - Linux on amd64
  • linux/arm64 - Linux on ARM64 (including Raspberry Pi)
  • windows/amd64 - Windows on amd64

Linking

The Go module is configured to statically link with the RaptorQ library. This means the library code is included in the final binary, making it self-contained and avoiding runtime dependencies on shared libraries.

Usage

To use this package in your Go project:

go get github.com/LumeraProtocol/rq-go

Then import it in your code:

import "github.com/LumeraProtocol/rq-go"

Example

package main

import (
	"fmt"
	"github.com/LumeraProtocol/rq-go"
)

func main() {
	// Create a new RaptorQ processor with default settings
	processor, err := raptorq.NewDefaultRaptorQProcessor()
	if err != nil {
		panic(err)
	}
	defer processor.Free()

	// Get library version
	version := raptorq.GetVersion()
	fmt.Printf("RaptorQ library version: %s\n", version)

	// Use the processor to encode/decode files
	// See the test file for examples
}

License

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

Documentation

Index

Constants

View Source
const (
	DefaultSymbolSize       uint16 = 65535
	DefaultRedundancyFactor uint8  = 4
	DefaultMaxMemoryMB      uint64 = 16 * 1024
	DefaultConcurrencyLimit uint64 = 4

	//MaxMemoryMB_1GB uint64 = 1 * 1024
	MaxMemoryMB_4GB uint64 = 4 * 1024
)

Default configuration values These values match the defaults in the Rust library src/lib.rs

Variables

This section is empty.

Functions

func GetVersion

func GetVersion() string

GetVersion returns the library version

Types

type Block

type Block struct {
	BlockID            uint64  `json:"block_id"`
	EncoderParameters  []uint8 `json:"encoder_parameters"`
	OriginalOffset     uint64  `json:"original_offset"`
	Size               uint64  `json:"size"`
	SymbolsCount       uint32  `json:"symbols_count"`
	SourceSymbolsCount uint32  `json:"source_symbols_count"`
	Hash               string  `json:"hash"`
}

Block represents information about a processed block

type ProcessResult

type ProcessResult struct {
	TotalSymbolsCount  uint32  `json:"total_symbols_count"`
	TotalRepairSymbols uint32  `json:"total_repair_symbols"`
	SymbolsDirectory   string  `json:"symbols_directory"`
	Blocks             []Block `json:"blocks,omitempty"`
	LayoutFilePath     string  `json:"layout_file_path"`
}

ProcessResult holds information about the processing results

type ProcessorConfig

type ProcessorConfig struct {
	SymbolSize       uint16 `json:"symbol_size"`
	RedundancyFactor uint8  `json:"redundancy_factor"`
	MaxMemoryMB      uint64 `json:"max_memory_mb"`
	ConcurrencyLimit uint64 `json:"concurrency_limit"`
}

ProcessorConfig holds configuration for the RaptorQ processor

type RaptorQProcessor

type RaptorQProcessor struct {
	SessionID uintptr
}

RaptorQProcessor represents a RaptorQ processing session

func NewDefaultRaptorQProcessor

func NewDefaultRaptorQProcessor() (*RaptorQProcessor, error)

NewDefaultRaptorQProcessor creates a new RaptorQ processor with default configuration

func NewRaptorQProcessor

func NewRaptorQProcessor(symbolSize uint16, redundancyFactor uint8, maxMemoryMB uint64, concurrencyLimit uint64) (*RaptorQProcessor, error)

NewRaptorQProcessor creates a new RaptorQ processor with the specified configuration

func (*RaptorQProcessor) CreateMetadata

func (p *RaptorQProcessor) CreateMetadata(inputPath, layoutFile string, blockSize int) (*ProcessResult, error)

CreateMetadata creates metadata for RaptorQ encoding without writing symbol data It writes the layout information to the specified layout file

func (*RaptorQProcessor) DecodeSymbols

func (p *RaptorQProcessor) DecodeSymbols(symbolsDir, outputPath, layoutPath string) error

DecodeSymbols decodes RaptorQ symbols back to the original file

func (*RaptorQProcessor) EncodeFile

func (p *RaptorQProcessor) EncodeFile(inputPath, outputDir string, blockSize int) (*ProcessResult, error)

EncodeFile encodes a file using RaptorQ

func (*RaptorQProcessor) Free

func (p *RaptorQProcessor) Free() bool

Free manually frees the RaptorQ session Returns true if the session was successfully freed, false otherwise

func (*RaptorQProcessor) GetRecommendedBlockSize

func (p *RaptorQProcessor) GetRecommendedBlockSize(fileSize uint64) int

GetRecommendedBlockSize returns a recommended block size for a file

Jump to

Keyboard shortcuts

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