Commit 68bd1aee authored by Chunchi Che's avatar Chunchi Che

add BufferWriter in rust-src

parent d48085ca
Pipeline #20741 failed with stages
in 8 minutes and 18 seconds
......@@ -72,3 +72,36 @@ impl BufferReader {
ret
}
}
#[wasm_bindgen]
pub struct BufferWriter {
array: Vec<u8>,
}
#[wasm_bindgen]
impl BufferWriter {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
Self { array: Vec::new() }
}
pub fn writeUint8(&mut self, value: u8) {
self.array.push(value);
}
pub fn writeInt8(&mut self, value: i8) {
self.array.extend(value.to_le_bytes());
}
pub fn writeUint32(&mut self, value: u32) {
self.array.extend(value.to_le_bytes());
}
pub fn writeInt32(&mut self, value: i32) {
self.array.extend(value.to_le_bytes());
}
pub fn toArray(self) -> Vec<u8> {
self.array
}
}
......@@ -5,7 +5,7 @@ mod buffer;
mod utils;
pub use adapters::*;
pub use buffer::BufferReader;
pub use buffer::{BufferReader, BufferWriter};
pub use utils::set_panic_hook;
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment