INNER CODE UNIT · Rust
write_to_guest_vec
lunatic-solutions/lunatic · crates/lunatic-common-api/src/lib.rs:60
pub async fn write_to_guest_vec<T: Send>(
caller: &mut Caller<'_, T>,
memory: &Memory,
data: &[u8],
len_ptr: u32,
) -> Result<u32> {
let alloc_len = data.len();
let alloc_ptr = allocate_guest_memory(caller, alloc_len as u32).await?;
let (memory_slice, _) = memory.data_and_store_mut(&mut (*caller));
let mut alloc_vec = memory_slice
.get_mut(alloc_ptr as usize..(alloc_ptr as usize + alloc_len))
.context("allocated memory does not exist")?;
alloc_vec.write_all(data)?;
memory.write(caller, len_ptr as usize, &alloc_len.to_le_bytes())?;