ReedSolomonEx

Note: This is a fork of ewildgoose/rs_protect with the intention to experiment with new approaches and extend platform support.

ReedSolomonEx is an Elixir wrapper around the reed-solomon Rust crate using Rustler. It provides fast, pure-Rust Reed-Solomon encoding and decoding for binary data. Protection is implemented on a per byte basis and an ECC/Parity code will be generated of length N, which will protect and correct against up to N/2 errors or erasures in the source. This makes it useful for protecting short binaries against corruption in transmission

Differences from Upstream

This fork diverges from the original with the following goals:

Features

Installation

Add to mix.exs:

def deps do
  [
    {:reed_solomon_ex, "~> 0.1"}
  ]
end

Usage

iex> data = <<1, 2, 3, 4, 5>>
iex> {:ok, encoded} = ReedSolomonEx.encode(data, 4)
iex> ReedSolomonEx.is_corrupted(encoded, 4)
{:ok, false}
iex> {:ok, decoded} = ReedSolomonEx.correct(encoded, 4)
decoded == data

iex> corrupted = :binary.replace(encoded, <<2>>, <<42>>, global: false)
iex> ReedSolomonEx.is_corrupted(corrupted, 4)
{:ok, true}
iex> {:ok, {recovered, count}} = ReedSolomonEx.correct_err_count(corrupted, 4)
{:ok, {^data, 1}}

Dynamic Parity Strategy

def choose_parity(bytes) when byte_size(bytes) > 80, do: 16
def choose_parity(_), do: 4

Development

This project uses devenv for development environment setup.

# Enter the development shell
devenv shell

# Or use direnv for automatic shell activation
direnv allow

Building

# Force local build (for development)
REED_SOLOMON_EX_FORCE_BUILD=1 mix compile

# Run tests
mix test