diff --git a/Cargo.toml b/Cargo.toml index 9c53c51..084b5f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/Makefile b/Makefile index e975c88..eb9575f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/examples/index.html b/examples/index.html deleted file mode 100644 index bb45771..0000000 --- a/examples/index.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - hello-wasm example - - - - - diff --git a/examples/main.rs b/examples/main.rs index 4cf916e..bdd5b33 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -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 = 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."); } diff --git a/src/decoder.rs b/src/decoder.rs index eb34b02..6ac2323 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -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> { 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 = 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; diff --git a/src/encoder.rs b/src/encoder.rs index 1e7ccbb..998b4de 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -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); diff --git a/src/lib.rs b/src/lib.rs index a41df44..8d9b1a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/wasm.rs b/src/wasm.rs deleted file mode 100644 index 378fe34..0000000 --- a/src/wasm.rs +++ /dev/null @@ -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> { - 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 { - self.encoder - .get_encoded_packets(repair_packets_per_block) - .iter() - .map(|packet| Uint8Array::from(packet.serialize().as_slice())) - .collect() - } -}