MCPcopy Create free account
hub / github.com/bytecodealliance/WASI-Virt / write_slice

Method write_slice

src/data.rs:89–98  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

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

Callers 1

create_io_virtFunction · 0.80

Calls 2

stack_allocMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected