kp and kl are the key pointer and length in wasm memory, vp and vl are for the value
(mut ctx: FunctionEnvMut<Ctx>, kp: i32, kl: i32, vp: i32, vl: i32)
| 42 | |
| 43 | /// kp and kl are the key pointer and length in wasm memory, vp and vl are for the value |
| 44 | fn kv_put(mut ctx: FunctionEnvMut<Ctx>, kp: i32, kl: i32, vp: i32, vl: i32) -> i32 { |
| 45 | let (c, s) = ctx.data_and_store_mut(); |
| 46 | let mut key = vec![0u8; kl as usize]; |
| 47 | let mut val = vec![0u8; vl as usize]; |
| 48 | let m = c.mem.as_ref().unwrap().view(&s); |
| 49 | if m.read(kp as u64, &mut key).is_err() || m.read(vp as u64, &mut val).is_err() { |
| 50 | return -1; |
| 51 | } |
| 52 | c.kv.insert(key, val); |
| 53 | 0 |
| 54 | } |
| 55 | |
| 56 | // // p and l are the buffer pointer and length in wasm memory. |
| 57 | // fn get_code(mut ctx:FunctionEnvMut<Ctx>, p: i32, l: i32) -> i32 { |