🎉 Deserialize shape data in wasm

This commit is contained in:
Belén Albeza 2024-12-09 14:30:03 +01:00
parent 22b01c63b5
commit 0bfcc1f854
6 changed files with 140 additions and 18 deletions

View file

@ -7,7 +7,7 @@ pub extern "C" fn alloc_bytes(len: usize) -> *mut u8 {
panic!("Bytes already allocated");
}
let mut buffer = Box::new(Vec::<u8>::with_capacity(len));
let mut buffer = Box::new(vec![0u8; len]);
let ptr = buffer.as_mut_ptr();
unsafe { BUFFERU8 = Some(buffer) };
@ -23,3 +23,8 @@ pub fn buffer_ptr() -> *mut u8 {
let buffer = unsafe { BUFFERU8.as_mut() }.expect("uninitializied buffer");
buffer.as_mut_ptr()
}
pub fn bytes() -> Vec<u8> {
let buffer = unsafe { BUFFERU8.take() }.expect("uninitialized buffer");
*buffer
}