MCPcopy Index your code
hub / github.com/RustPython/RustPython / kv_get

Function kv_get

example_projects/wasm32_without_js/wasm-runtime/src/main.rs:13–41  ·  view source on GitHub ↗

kp and kl are the key pointer and length in wasm memory, vp and vl are for the return value if read value is bigger than vl then it will be truncated to vl, returns read bytes

(mut ctx: FunctionEnvMut<Ctx>, kp: i32, kl: i32, vp: i32, vl: i32)

Source from the content-addressed store, hash-verified

11/// kp and kl are the key pointer and length in wasm memory, vp and vl are for the return value
12/// if read value is bigger than vl then it will be truncated to vl, returns read bytes
13fn kv_get(mut ctx: FunctionEnvMut<Ctx>, kp: i32, kl: i32, vp: i32, vl: i32) -> i32 {
14 let (c, s) = ctx.data_and_store_mut();
15 let mut key = vec![0u8; kl as usize];
16 if c.mem
17 .as_ref()
18 .unwrap()
19 .view(&s)
20 .read(kp as u64, &mut key)
21 .is_err()
22 {
23 return -1;
24 }
25 match c.kv.get(&key) {
26 Some(val) => {
27 let len = val.len().min(vl as usize);
28 if c.mem
29 .as_ref()
30 .unwrap()
31 .view(&s)
32 .write(vp as u64, &val[..len])
33 .is_err()
34 {
35 return -1;
36 }
37 len as i32
38 }
39 None => 0,
40 }
41}
42
43/// kp and kl are the key pointer and length in wasm memory, vp and vl are for the value
44fn kv_put(mut ctx: FunctionEnvMut<Ctx>, kp: i32, kl: i32, vp: i32, vl: i32) -> i32 {

Callers

nothing calls this directly

Calls 8

is_errMethod · 0.80
readMethod · 0.45
unwrapMethod · 0.45
as_refMethod · 0.45
getMethod · 0.45
minMethod · 0.45
lenMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected