Allocate some bytes into the data section, return the pointer Note this is only safe for T being repr(C) / packed
(&mut self, data: &[T])
| 87 | /// Allocate some bytes into the data section, return the pointer |
| 88 | /// Note this is only safe for T being repr(C) / packed |
| 89 | pub fn write_slice<T: WasmEncode>(&mut self, data: &[T]) -> Result<u32> { |
| 90 | let size = T::size(); |
| 91 | let bytes = self.stack_alloc(data.len() * size, T::align())?; |
| 92 | let mut cursor = 0; |
| 93 | for item in data { |
| 94 | item.encode(&mut bytes[cursor..cursor + size]); |
| 95 | cursor += size; |
| 96 | } |
| 97 | Ok(self.stack_ptr as u32) |
| 98 | } |
| 99 | |
| 100 | /// Allocate a static string and return its pointer |
| 101 | /// If the string already exists, return the existing pointer |
no test coverage detected