1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! [](https://github.com/ypo/raptor/actions/workflows/rust.yml)
//! [](https://codecov.io/gh/ypo/raptor)
//! [](https://crates.io/crates/raptor-code/)
//!
//! # Raptor Code
//!
//! A Rust library for implementing Forward Error Correction (FEC) using Raptor
//! codes.
//!
//! Raptor codes are a class of FEC codes that are designed to be highly
//! efficient in the presence of packet erasures. This library provides
//! functionality for encoding source blocks into encoding symbols and decoding
//! source blocks from a set of encoding symbols.
//!
//! This library implements on the fly Gaussian Elimination to spread decoding
//! complexity during packets reception.
//!
//! # Example : Source Block Encoder/Decoder
//!
//! Encode and decode a source block using `raptor_code::encode_source_block`
//! and `raptor_code::decode_source_block`
//!
//!
//! ```
//! let source_block_data: Vec<u8> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
//! let max_source_symbols = 4;
//! let nb_repair = 3;
//! let source_block_length = source_block_data.len();
//!
//! // Step 1 - Generate the encoding symbols (source symbols + repair symbols)
//! let (encoding_symbols, nb_source_symbols) =
//! raptor_code::encode_source_block(&source_block_data, max_source_symbols, nb_repair).unwrap();
//!
//! // Step 2 - Re-construct the source data from the encoding symbols
//! let mut received_symbols: Vec<Option<Vec<u8>>> = encoding_symbols
//! .into_iter()
//! .map(|symbols| Some(symbols))
//! .collect();
//! // simulate encoding symbol lost
//! received_symbols[0] = None;
//!
//! let reconstructed_data = raptor_code::decode_source_block(
//! &received_symbols,
//! nb_source_symbols as usize,
//! source_block_length,
//! )
//! .unwrap();
//!
//! // Source data and decoded data should be identical
//! assert!(reconstructed_data == source_block_data)
//! ```
//!
//! # Example : On the fly encoder
//!
//! ```
//! let source_data: Vec<u8> = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
//! let max_source_symbols = 4;
//! let nb_repair = 3;
//!
//! let mut encoder = raptor_code::SourceBlockEncoder::new(&source_data, max_source_symbols).unwrap();
//! let n = encoder.nb_source_symbols() + nb_repair;
//!
//! for esi in 0..n as u32 {
//! let encoding_symbol = encoder.fountain(esi);
//! // TODO transfer symbol over Network
//! // network_push_pkt(encoding_symbol);
//! }
//! ```
//! # Example : On the fly decoder
//!
//! ```
//! let encoding_symbol_length = 1024;
//! let nb_source_symbols = 4; // Number of source symbols in the source block
//! let source_block_length = encoding_symbol_length * nb_source_symbols; // Total size size of the block;
//! let mut n = 0u32;
//! let mut decoder = raptor_code::SourceBlockDecoder::new(nb_source_symbols);
//!
//! while decoder.fully_specified() == false {
//! //TODO replace the following line with pkt received from network
//! let (encoding_symbol, esi) = (vec![0; encoding_symbol_length],n);
//! decoder.push_encoding_symbol(&encoding_symbol, esi);
//! n += 1;
//! }
//!
//! let source_block = decoder.decode(source_block_length as usize);
//! ```
//!
//! # Credit
//!
//! RFC 5053 <https://www.rfc-editor.org/rfc/rfc5053.html>
//!
//! On the fly Gaussian Elimination for LT codes, Valerio Bioglio, Marco
//! Grangetto, 2009
//!
//! Reuse ideas and concepts of [gofountain](https://github.com/google/gofountain)
extern crate alloc;
extern crate std;
pub use ;
pub use ;