Expand description
Reed-Solomon erasure coding over GF(2^8) — the wire codec’s redundant knob.
Split a payload into k data shards plus n − k parity shards; a receiver
reconstructs the EXACT payload from ANY k of the n shards. This is the
reconstructable axis no general wire format ships: drop, duplicate, or reorder up to
n − k shards on a lossy link (UDP / multicast / BLE / LoRa) and the message still
arrives, with no retransmit and no coordination.
The code is systematic (the first k shards ARE the data chunks, so lossless
delivery costs no decode) and MDS (any k shards suffice). The encoding matrix
is a Vandermonde matrix made systematic by multiplying through the inverse of its own
top k×k block: every k-row subset stays invertible, which is exactly the
any-k-of-n guarantee.
Functions§
- decode
- Reconstruct the payload from ANY
k(index, shard) pairs out of then.Noneif fewer thankdistinct valid shards are present (then the message is unrecoverable). - encode
- Encode
dataintonshards (kdata +n − kparity). Returns the original byte length (for un-padding on decode) and the shards.Nonefor a degenerate(k, n)(k == 0,n < k, orn > 256— GF(2^8) has only 256 distinct nodes). - frame_
redundant - Split a message into
nself-describing FEC shards (kdata +n − kparity), each independently transmittable. A receiver reconstructs the exact message from ANYkviareconstruct_redundant.msg_idgroups a message’s shards on the wire. - reconstruct_
redundant - Reconstruct a message from a bag of received FEC shards. Groups by message id and
reconstructs the first message that has at least
kdistinct shards present; returns its(msg_id, payload). Shards from other messages, malformed shards, header- inconsistent shards, and duplicate indices are ignored.Noneif no message has reached itsk-shard threshold. - shard_
header - Peek a framed shard’s identity without copying its payload:
(msg_id, k, n).Noneifbytesis not a FEC shard (wrong magic / too short). Lets a receiver group shards by message and know how many it needs (k) before reconstructing.