Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve 2.0 TODOs #166

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ impl Decoder {

let mut decoders = vec![];
for i in 0..zl {
decoders.push(SourceBlockDecoder::new2(
decoders.push(SourceBlockDecoder::new(
i as u8,
&config,
u64::from(kl) * u64::from(config.symbol_size()),
));
}

for i in zl..(zl + zs) {
decoders.push(SourceBlockDecoder::new2(
decoders.push(SourceBlockDecoder::new(
i as u8,
&config,
u64::from(ks) * u64::from(config.symbol_size()),
Expand Down Expand Up @@ -137,18 +137,7 @@ pub struct SourceBlockDecoder {
}

impl SourceBlockDecoder {
#[deprecated(
since = "1.3.0",
note = "Use the new2() function instead. In version 2.0, that function will replace this one"
)]
#[cfg(feature = "std")]
pub fn new(source_block_id: u8, symbol_size: u16, block_length: u64) -> SourceBlockDecoder {
let config = ObjectTransmissionInformation::new(0, symbol_size, 0, 1, 1);
SourceBlockDecoder::new2(source_block_id, &config, block_length)
}

// TODO: rename this to new() in version 2.0
pub fn new2(
pub fn new(
source_block_id: u8,
config: &ObjectTransmissionInformation,
block_length: u64,
Expand Down Expand Up @@ -494,9 +483,9 @@ mod codec_tests {
}

let config = ObjectTransmissionInformation::new(0, symbol_size as u16, 0, 1, 1);
let encoder = SourceBlockEncoder::new2(1, &config, &data);
let encoder = SourceBlockEncoder::new(1, &config, &data);

let mut decoder = SourceBlockDecoder::new2(1, &config, elements as u64);
let mut decoder = SourceBlockDecoder::new(1, &config, elements as u64);
decoder.set_sparse_threshold(sparse_threshold);

let mut result = None;
Expand Down Expand Up @@ -555,11 +544,11 @@ mod codec_tests {
let total_bytes: usize = 1024 * 1024;
let iterations = total_bytes / elements;
let config = ObjectTransmissionInformation::new(0, symbol_size, 0, 1, 1);
let encoder = SourceBlockEncoder::new2(1, &config, &data);
let encoder = SourceBlockEncoder::new(1, &config, &data);
let elements_and_overhead = (symbol_count as f64 * (1.0 + overhead)) as u32;
let mut packets = encoder.repair_packets(0, iterations as u32 * elements_and_overhead);
for _ in 0..iterations {
let mut decoder = SourceBlockDecoder::new2(1, &config, elements as u64);
let mut decoder = SourceBlockDecoder::new(1, &config, elements as u64);
let start = packets.len() - elements_and_overhead as usize;
decoder.decode(packets.drain(start..));
}
Expand Down Expand Up @@ -600,12 +589,12 @@ mod codec_tests {
let config = ObjectTransmissionInformation::new(0, 8, 0, 1, 1);
let encoder = if pre_plan {
let plan = SourceBlockEncodingPlan::generate(symbol_count as u16);
SourceBlockEncoder::with_encoding_plan2(1, &config, &data, &plan)
SourceBlockEncoder::with_encoding_plan(1, &config, &data, &plan)
} else {
SourceBlockEncoder::new2(1, &config, &data)
SourceBlockEncoder::new(1, &config, &data)
};

let mut decoder = SourceBlockDecoder::new2(1, &config, elements as u64);
let mut decoder = SourceBlockDecoder::new(1, &config, elements as u64);
decoder.set_sparse_threshold(sparse_threshold);

let mut result = None;
Expand Down
31 changes: 3 additions & 28 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Encoder {
let plan = SourceBlockEncodingPlan::generate(symbol_count as u16);
cached_plan = Some(plan);
}
block_encoders.push(SourceBlockEncoder::with_encoding_plan2(
block_encoders.push(SourceBlockEncoder::with_encoding_plan(
i as u8,
&config,
block,
Expand Down Expand Up @@ -197,15 +197,6 @@ pub struct SourceBlockEncoder {
}

impl SourceBlockEncoder {
#[deprecated(
since = "1.3.0",
note = "Use the new2() function instead. In version 2.0, that function will replace this one"
)]
pub fn new(source_block_id: u8, symbol_size: u16, data: &[u8]) -> SourceBlockEncoder {
let config = ObjectTransmissionInformation::new(0, symbol_size, 0, 1, 1);
SourceBlockEncoder::new2(source_block_id, &config, data)
}

fn create_symbols(config: &ObjectTransmissionInformation, data: &[u8]) -> Vec<Symbol> {
assert_eq!(data.len() % config.symbol_size() as usize, 0);
if config.sub_blocks() > 1 {
Expand Down Expand Up @@ -237,8 +228,7 @@ impl SourceBlockEncoder {
}
}

// TODO: rename this to new() in version 2.0
pub fn new2(
pub fn new(
source_block_id: u8,
config: &ObjectTransmissionInformation,
data: &[u8],
Expand All @@ -258,22 +248,7 @@ impl SourceBlockEncoder {
}
}

#[deprecated(
since = "1.3.0",
note = "Use the with_encoding_plan2() function instead. In version 2.0, that function will replace this one"
)]
pub fn with_encoding_plan(
source_block_id: u8,
symbol_size: u16,
data: &[u8],
plan: &SourceBlockEncodingPlan,
) -> SourceBlockEncoder {
let config = ObjectTransmissionInformation::new(0, symbol_size, 0, 1, 1);
SourceBlockEncoder::with_encoding_plan2(source_block_id, &config, data, plan)
}

// TODO: rename this to with_encoding_plan() in version 2.0
pub fn with_encoding_plan2(
source_block_id: u8,
config: &ObjectTransmissionInformation,
data: &[u8],
Expand Down Expand Up @@ -563,7 +538,7 @@ mod tests {
fn encoding_creates_expected_packets() {
let symbol_size = 2;
let data: [u8; 6] = [0, 1, 2, 3, 4, 5];
let encoder = SourceBlockEncoder::new2(
let encoder = SourceBlockEncoder::new(
0,
&ObjectTransmissionInformation::new(0, symbol_size, 1, 1, 1),
&data,
Expand Down
Loading