RaptorQ forward error correction (RFC 6330).
Quick start
# Encode: chunk data into K symbols of size `sym_size` (pads if necessary)
data = File.read!("myfile.dat")
k = 10
sym_size = ceil(byte_size(data) / k)
{:ok, state} = Raptorq.encode(data, k, sym_size)
# Generate repair symbols for any ISI ≥ K'
c = Map.get(state, :c)
p = Map.get(state, :params)
repair_1 = Raptorq.repair(c, p, 100_000)
# Decode: recover data gracefully using the StreamingDecoder
decoder = Raptorq.StreamingDecoder.new(k, byte_size(data))
{:ok, :incomplete, decoder} = Raptorq.StreamingDecoder.add_symbol(decoder, 0, sym_0)
# ... receive more symbols ...
{:ok, {:decoded, data}, _decoder} = Raptorq.StreamingDecoder.add_symbol(decoder, 100_000, repair_1)Architecture
The source data is split into K equal-sized symbols. Using the SIOP table, K' ≥ K is chosen, and the K'-K tail symbols are zero- padded. The constraint matrix A (L = S+H+K' rows/columns) is built linking intermediate symbols C to the source symbols via A·C = D.
Encoding symbols for any ISI (0 … 2²⁰−1) are linear combinations of C produced by Tuple[K', ISI] (RFC 6330 §5.3.5.4). The receiver builds a system from LDPC+HDPC rows (always D=0) and G_ENC rows for received ISIs, then solves for C to recover the source data.
Performance
Uses the 5-phase sparse solver (Raptorq.Solver) for efficient
O(L²) decoding of the intermediate symbols C.
Summary
Functions
Decode received symbols to recover original source data.
Encode source data for block of K source symbols.
Encode source data into exactly k source symbols of sym_size.
Generate one repair symbol for the given ISI.
Functions
Decode received symbols to recover original source data.
received is a list of {isi, symbol_binary} tuples.
k is the number of source symbols in the original block.
data_size (optional) truncates output to the original data size.
Encode source data for block of K source symbols.
data is the source data as a binary. k is the number of source
symbols in the block.
The data length must be exactly k * symbol_size (i.e. divisible by k).
For automatic chunking with padding, use encode/3.
Returns {:ok, %{c: intermediate_symbols, params: siop_params, symbol_size: sym_size, k_prime: kp, source_symbols: source_syms}}.
Encode source data into exactly k source symbols of sym_size.
Pads the data with trailing zeros if necessary to reach k * sym_size.
Generate one repair symbol for the given ISI.
c_syms is the list of L intermediate symbols.
params is the SIOP parameter map produced by encode/2.
isi is the encoding symbol ID (any non-negative integer; use
ISIs ≥ K' for true repair symbols, or < K' to regenerate source
symbols). The symbol size is inferred from c_syms.
Returns the repair symbol as a binary.