Remove wasm support

This commit is contained in:
Christopher Berner 2023-11-25 11:06:51 -08:00
parent cd1df04d92
commit 99cd7d70b5
8 changed files with 25 additions and 132 deletions

@ -15,8 +15,6 @@ crate-type = ["lib"]
[dependencies]
serde = {version = "1.0.102", features=["std", "derive"], optional = true}
pyo3 = {version = "0.20", features=["extension-module", "abi3-py37"], optional = true }
wasm-bindgen = {version = "0.2", optional = true}
js-sys = {version = "0.3.60", optional = true}
[dev-dependencies]
criterion = "0.3"
@ -57,4 +55,3 @@ benchmarking = ["std"]
python = ["pyo3", "std"]
serde_support = ["serde", "std"]
std = []
wasm = ["wasm-bindgen", "js-sys", "std"]

@ -52,6 +52,3 @@ install_py: pre
test_py: install_py
python3 -m unittest discover
build_wasm: pre
wasm-pack build --target web --features wasm

@ -1,37 +0,0 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>hello-wasm example</title>
</head>
<body>
<script type="module">
import init, { Decoder, Encoder } from "../pkg/raptorq.js";
init().then(() => {
let test = Array.from({length: 10000}, () => Math.floor(Math.random() * 100));
let data = Uint8Array.from(test);
let encoder = Encoder.with_defaults(data, 512);
let packets = encoder.encode(42);
console.log(`data ${data} encoded packets are ${packets}`);
let shuffledPackets = packets.sort((a, b) => 0.5 - Math.random());
console.log(`data ${data} encoded packets are ${packets}`);
let decoder = Decoder.with_defaults(BigInt(data.length), 512);
let decodedData;
for (let i = 0; i < shuffledPackets.length; i++) {
console.log(i);
decodedData = decoder.decode(packets[i]);
if (decodedData) {
break;
}
}
console.log(data);
console.log(decodedData);
console.log(JSON.stringify(data) === JSON.stringify(decodedData));
});
</script>
</body>
</html>

@ -1,13 +1,13 @@
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
use rand::seq::SliceRandom;
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
use rand::Rng;
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
use raptorq::{Decoder, Encoder, EncodingPacket};
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
fn main() {
// Generate some random data to send
let mut data: Vec<u8> = vec![0; 10_000];
@ -50,7 +50,7 @@ fn main() {
assert_eq!(result.unwrap(), data);
}
#[cfg(any(feature = "python", feature = "wasm"))]
#[cfg(feature = "python")]
fn main() {
panic!("This is not indented to compile for `python` and `wasm` features.");
panic!("This is not indented to compile for `python` feature.");
}

@ -66,10 +66,7 @@ impl Decoder {
}
}
#[cfg(all(
any(test, feature = "benchmarking"),
not(any(feature = "python", feature = "wasm"))
))]
#[cfg(all(any(test, feature = "benchmarking"), not(feature = "python")))]
pub fn set_sparse_threshold(&mut self, value: u32) {
for block_decoder in self.block_decoders.iter_mut() {
block_decoder.set_sparse_threshold(value);
@ -97,7 +94,7 @@ impl Decoder {
Some(result)
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
pub fn add_new_packet(&mut self, packet: EncodingPacket) {
let block_number = packet.payload_id.source_block_number() as usize;
if self.blocks[block_number].is_none() {
@ -106,7 +103,7 @@ impl Decoder {
}
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
pub fn get_result(&self) -> Option<Vec<u8>> {
for block in self.blocks.iter() {
if block.is_none() {
@ -349,14 +346,14 @@ impl SourceBlockDecoder {
#[cfg(feature = "std")]
#[cfg(test)]
mod codec_tests {
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
use crate::Decoder;
use crate::SourceBlockEncoder;
use crate::SourceBlockEncodingPlan;
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
use crate::{Encoder, EncoderBuilder};
use crate::{ObjectTransmissionInformation, SourceBlockDecoder};
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
use rand::seq::SliceRandom;
use rand::Rng;
use std::{
@ -368,19 +365,19 @@ mod codec_tests {
vec::Vec,
};
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
#[test]
fn random_erasure_dense() {
random_erasure(99_999);
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
#[test]
fn random_erasure_sparse() {
random_erasure(0);
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
fn random_erasure(sparse_threshold: u32) {
let elements: usize = rand::thread_rng().gen_range(1..1_000_000);
let mut data: Vec<u8> = vec![0; elements];
@ -413,7 +410,7 @@ mod codec_tests {
assert_eq!(result.unwrap(), data);
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
#[test]
fn sub_block_erasure() {
let elements: usize = 10_000;

@ -452,9 +452,9 @@ mod tests {
use crate::systematic_constants::{
calculate_p1, num_ldpc_symbols, systematic_index, MAX_SOURCE_SYMBOLS_PER_BLOCK,
};
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
use crate::{Encoder, EncoderBuilder, EncodingPacket, ObjectTransmissionInformation};
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
use std::collections::HashSet;
const SYMBOL_SIZE: usize = 4;
@ -555,7 +555,7 @@ mod tests {
}
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
#[test]
fn test_builder() {
let data = vec![0, 1, 2, 3];
@ -565,7 +565,7 @@ mod tests {
assert_eq!(builder.build(&data), encoder);
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
#[test]
fn padding_constraint_exact() {
let packet_size: u16 = 1024;
@ -574,7 +574,7 @@ mod tests {
padding_constraint(packet_size, padding_size, data_size);
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
#[test]
fn padding_constraint_42_bytes() {
let packet_size: u16 = 1024;
@ -583,7 +583,7 @@ mod tests {
padding_constraint(packet_size, padding_size, data_size);
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
fn padding_constraint(packet_size: u16, padding_size: usize, data_size: usize) {
let data = gen_test_data(data_size);
let encoder = Encoder::with_defaults(&data, packet_size);
@ -604,7 +604,7 @@ mod tests {
assert_eq!(data[..], padded_data[..data_size]);
}
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
#[test]
fn unique_blocks() {
let data = gen_test_data(120);

@ -34,18 +34,16 @@ mod sparse_vec;
mod symbol;
mod systematic_constants;
mod util;
#[cfg(feature = "wasm")]
mod wasm;
pub use crate::base::partition;
pub use crate::base::EncodingPacket;
pub use crate::base::ObjectTransmissionInformation;
pub use crate::base::PayloadId;
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
pub use crate::decoder::Decoder;
pub use crate::decoder::SourceBlockDecoder;
pub use crate::encoder::calculate_block_offsets;
#[cfg(not(any(feature = "python", feature = "wasm")))]
#[cfg(not(feature = "python"))]
pub use crate::encoder::Encoder;
pub use crate::encoder::EncoderBuilder;
pub use crate::encoder::SourceBlockEncoder;
@ -57,10 +55,6 @@ pub use crate::python::Decoder;
#[cfg(feature = "python")]
pub use crate::python::Encoder;
pub use crate::systematic_constants::extended_source_block_symbols;
#[cfg(feature = "wasm")]
pub use crate::wasm::Decoder as WasmDecoder;
#[cfg(feature = "wasm")]
pub use crate::wasm::Encoder as WasmEncoder;
#[cfg(feature = "benchmarking")]
pub use crate::constraint_matrix::generate_constraint_matrix;

@ -1,55 +0,0 @@
use std::vec::Vec;
use crate::base::{EncodingPacket, ObjectTransmissionInformation};
use crate::decoder::Decoder as DecoderNative;
use crate::encoder::Encoder as EncoderNative;
use js_sys::Uint8Array;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct Decoder {
decoder: DecoderNative,
}
#[wasm_bindgen]
impl Decoder {
#[wasm_bindgen]
pub fn with_defaults(transfer_length: u64, maximum_transmission_unit: u16) -> Decoder {
let config = ObjectTransmissionInformation::with_defaults(
transfer_length,
maximum_transmission_unit,
);
Decoder {
decoder: DecoderNative::new(config),
}
}
#[wasm_bindgen]
pub fn decode(&mut self, packet: &[u8]) -> Option<Vec<u8>> {
self.decoder.decode(EncodingPacket::deserialize(packet))
}
}
#[wasm_bindgen]
pub struct Encoder {
encoder: EncoderNative,
}
#[wasm_bindgen]
impl Encoder {
#[wasm_bindgen]
pub fn with_defaults(data: &[u8], maximum_transmission_unit: u16) -> Encoder {
Encoder {
encoder: EncoderNative::with_defaults(data, maximum_transmission_unit),
}
}
#[wasm_bindgen]
pub fn encode(&mut self, repair_packets_per_block: u32) -> Vec<Uint8Array> {
self.encoder
.get_encoded_packets(repair_packets_per_block)
.iter()
.map(|packet| Uint8Array::from(packet.serialize().as_slice()))
.collect()
}
}