MCPcopy Create free account
hub / github.com/drogus/crows / consume_buffer

Method consume_buffer

wasm/src/lib.rs:392–417  ·  view source on GitHub ↗
(
        mut caller: Caller<'_, Self>,
        index: u32,
        ptr: u32,
        len: u32,
    )

Source from the content-addressed store, hash-verified

390 }
391
392 pub fn consume_buffer(
393 mut caller: Caller<'_, Self>,
394 index: u32,
395 ptr: u32,
396 len: u32,
397 ) -> anyhow::Result<()> {
398 let memory = get_memory(&mut caller)?;
399 let (slice, store) = memory.data_and_store_mut(&mut caller);
400
401 let buffer = store
402 .buffers
403 .try_remove(index as usize)
404 .ok_or(anyhow!("Could not remove slab buffer"))?;
405
406 anyhow::ensure!(
407 len as usize == buffer.len(),
408 "bad length passed to consume_buffer"
409 );
410
411 slice
412 .get_mut((ptr as usize)..((ptr + len) as usize))
413 .ok_or(anyhow!("Could not fetch slice from WASM memory"))?
414 .copy_from_slice(&buffer);
415
416 Ok(())
417 }
418}
419
420impl wasmtime_wasi::WasiView for WasiHostCtx {

Callers

nothing calls this directly

Calls 1

get_memoryFunction · 0.85

Tested by

no test coverage detected