Crate reed_solomon [−] [src]
Reed-Solomon BCH encoder and decoder suitable for no_std
environment
This library implements block encoder and decoder: error correction code is appended to original data
Example
extern crate reed_solomon; use reed_solomon::Encoder; use reed_solomon::Decoder; fn main() { let data = "Hello World!".as_bytes(); // Length of error correction code let ecc_len = 8; // Create encoder and decoder with let enc = Encoder::new(ecc_len); let dec = Decoder::new(ecc_len); // Encode data let encoded = enc.encode(&data[..]); // Simulate some transmission errors let mut corrupted = encoded.clone(); for i in 0..4 { corrupted[i] = 0xEE; } // Try to recover data let known_erasures = [0]; let recovered = dec.correct(&mut corrupted, Some(&known_erasures)).unwrap(); let orig_str = std::str::from_utf8(data).unwrap(); let recv_str = std::str::from_utf8(recovered.data()).unwrap(); println!("message: {:?}", orig_str); println!("original data: {:?}", data); println!("error correction code: {:?}", encoded.ecc()); println!("corrupted: {:?}", corrupted); println!("repaired: {:?}", recv_str); }Run
Unsafe
This library utilizes unsafe Slice::get_inchecked()
to improve speed where unchecked indexing
is safe and LLVM cannot drop boundary checks
Bandwidth
Software implementation is relatively slow because general purpose processors do not support Galois field arithmetic operations. For example, Galois field multiply requires test for 0, two table look-ups, modulo add, and anti-log table look-up.
Besides this performance bound, current implementation is not very optimal and performs some unnecessary memcpys
Encoder bandwidth using one Sandy Bridge core operating on 2.8 GHz
:
data |
ecc | bandwidth |
---|---|---|
251 | 4 | 105 MB/s |
239 | 16 | 33.98 MB/s |
223 | 32 | 16.32 MB/s |
Decoder bandwidth using one Sandy Bridge core operating on 2.8 GHz
:
data |
ecc | errors | bandwidth |
---|---|---|---|
251 | 4 | 0 |
48.70 MB/s |
1 | 16.90 MB/s |
||
2 | 15.29 MB/s |
||
239 | 16 | 0 | 10.74 MB/s |
1 | 4.84 MB/s |
||
8 | 3.78 MB/s |
||
223 | 32 | 0 | 4.88 MB/s |
1 | 2.32 MB/s |
||
16 | 1.73 MB/s |
Structs
Buffer |
Buffer for block encoded data |
Decoder |
Reed-Solomon BCH decoder |
Encoder |
Reed-Solomon BCH encoder |
Enums
ReedSolomonError |
Decoder error |