RSProtect (rs_protect v0.1.0)

View Source

Reed-Solomon encoder/decoder wrapper using Rust NIF.

Wraps the reed-solomon Rust crate to provide robust error-correcting codes for binary data. This library is suitable for transmitting binary packets over noisy links with optional parity.

Examples

iex> {:ok, codeword} = RSProtect.encode("hello", 4)
iex> {:ok, original} = RSProtect.correct(codeword, 4)
iex> original == "hello"
true

Summary

Functions

Decode/correct a binary codeword and attempts to correct up to N/2 errors.

Decode/Correct a binary codeword and attempts to correct up to N/2 errors. Same as correct/2, but returns the number of errors corrected.

Encodes a binary by appending N parity bytes for error correction.

Encodes a binary by appending N parity bytes for error correction. As encode/2, except that it only returns the parity bytes.

Check if a given codeword is corrupted (detectable by RS).

Functions

correct(codeword, parity_bytes, known_erasures)

@spec correct(binary(), non_neg_integer(), [byte()]) ::
  {:ok, binary()} | {:error, any()}

Decode/correct a binary codeword and attempts to correct up to N/2 errors.

Parameters

  • codeword: binary of data + parity
  • parity_bytes: number of parity bytes originally used
  • 'known_erasures': offsets of known erasures (optional)

Returns

  • {:ok, original_data} on success
  • :error if the message cannot be corrected

correct_err_count(codeword, parity_bytes, known_erasures)

Decode/Correct a binary codeword and attempts to correct up to N/2 errors. Same as correct/2, but returns the number of errors corrected.

Parameters

  • codeword: binary of data + parity
  • parity_bytes: number of parity bytes originally used
  • 'known_erasures': offsets of known erasures (optional)

Returns

  • {:ok, original_data, err_count} on success
  • :error if the message cannot be corrected

encode(data, parity_bytes)

Encodes a binary by appending N parity bytes for error correction.

Parameters

  • data: binary to encode
  • parity_bytes: number of bytes to use as parity (must be >= 2)

Returns

  • {:ok, binary} with appended parity
  • :error on failure

encode_ecc(data, parity_bytes)

Encodes a binary by appending N parity bytes for error correction. As encode/2, except that it only returns the parity bytes.

is_corrupted(codeword, parity_bytes)

Check if a given codeword is corrupted (detectable by RS).