Skip to content

Commit

Permalink
Fix source block numbering with uneven blocks
Browse files Browse the repository at this point in the history
This fixes a critical bug where blocks with ids after ZL, see section
4.4.1.2. in RFC, were incorrectly numbered during encoding
  • Loading branch information
cberner committed Mar 14, 2020
1 parent e12085c commit 7847099
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Encoder {

if zs > 0 {
let ks_plan = SourceBlockEncodingPlan::generate(ks as u16);
for i in 0..zs {
for i in zl..(zl + zs) {
let offset = ks as usize * config.symbol_size() as usize;
if data_index + offset <= data.len() {
blocks.push(SourceBlockEncoder::with_encoding_plan2(
Expand Down Expand Up @@ -417,7 +417,8 @@ mod tests {
use crate::systematic_constants::{
calculate_p1, num_ldpc_symbols, systematic_index, MAX_SOURCE_SYMBOLS_PER_BLOCK,
};
use crate::{Encoder, EncoderBuilder, EncodingPacket};
use crate::{Encoder, EncoderBuilder, EncodingPacket, ObjectTransmissionInformation};
use std::collections::HashSet;

const SYMBOL_SIZE: usize = 4;
const NUM_SYMBOLS: u32 = 100;
Expand Down Expand Up @@ -561,4 +562,17 @@ mod tests {
assert_eq!(data_size + padding_size, padded_data.len());
assert_eq!(data[..], padded_data[..data_size]);
}

#[test]
fn unique_blocks() {
let data = gen_test_data(120);
let config = ObjectTransmissionInformation::new(120, 10, 10, 0, 2);
let encoder = Encoder::new(&data, config);
assert!(encoder.get_block_encoders().len() > 1);
let mut ids = HashSet::new();
for block in encoder.get_block_encoders().iter() {
ids.insert(block.source_block_id);
}
assert_eq!(ids.len(), encoder.get_block_encoders().len());
}
}

0 comments on commit 7847099

Please sign in to comment.