4个稳定版本
1.0.6 | 2023年11月26日 |
---|---|
1.0.5 | 2023年2月8日 |
1.0.4 | 2023年1月25日 |
#1094 in 网络编程
每月 124 次下载
用于 flute
91KB
1K SLoC
raptor-code
Raptor Code
使用Raptor码实现前向纠错(FEC)的Rust库。
Raptor码是一种设计用于在包丢失情况下高效的前向纠错(FEC)码类。此库提供了将源块编码为编码符号和解码一组编码符号为源块的功能。
此库在接收数据包时实现即时高斯消元法以分散解码复杂性。
示例:源块编码器/解码器
使用raptor_code::encode_source_block
和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);
// 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)
示例:即时编码器
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);
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);
}
示例:即时解码器
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);
致谢
RFC 5053 https://www.rfc-editor.org/rfc/rfc5053.html
LT码的即时高斯消元法,Valerio Bioglio,Marco Grangetto,2009
重用gofountain中的想法和概念
许可证:MIT
依赖项
~105KB