use wasmtime::Caller;

pub fn read_plugin_memory<T>(caller: &mut Caller<'_, T>, ptr: u32, len: u32) -> Option<Vec<u8>> {
    let memory = caller.get_export("memory").and_then(|e| e.into_memory())?;
    let data = memory.data(caller);
    if (ptr as usize) + (len as usize) > data.len() {
        return None;
    }
    Some(data[ptr as usize..(ptr + len) as usize].to_vec())
}
