MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / encode

Function encode

wasm-pdk/src/lib.rs:266–286  ·  view source on GitHub ↗

Encode a primitive into a handle.

(v: Value)

Source from the content-addressed store, hash-verified

264
265/// Encode a primitive into a handle.
266pub fn encode(v: Value) -> Result<Handle> {
267 let raw = match v {
268 Value::None => unsafe { edge_encode(tag::NONE, core::ptr::null(), 0) },
269 Value::Bool(b) => {
270 let buf = [if b { 1u8 } else { 0u8 }];
271 unsafe { edge_encode(tag::BOOL, buf.as_ptr(), 1) }
272 }
273 Value::Int(i) => {
274 let buf = i.to_le_bytes();
275 unsafe { edge_encode(tag::INT, buf.as_ptr(), 16) }
276 }
277 Value::Float(f) => {
278 let buf = f.to_le_bytes();
279 unsafe { edge_encode(tag::FLOAT, buf.as_ptr(), 8) }
280 }
281 Value::Bytes(b) => unsafe { edge_encode(tag::BYTES, b.as_ptr(), b.len() as u32) },
282 Value::Raw(b) => unsafe { edge_encode(tag::RAW, b.as_ptr(), b.len() as u32) },
283 };
284 if raw == 0 { Err(Error::Runtime(alloc::string::String::from("encode failed"))) }
285 else { Ok(Handle::from_raw(raw)) }
286}
287
288/// Typed primitive value; composites (list, dict, set, instances) go through `Handle::call`.
289#[derive(Debug, Clone)]

Callers 13

get_handleMethod · 0.70
into_handleMethod · 0.70
str_listFunction · 0.50
groupsFunction · 0.50
spanFunction · 0.50
dumpsFunction · 0.50
parse_value_withFunction · 0.50
parse_objectFunction · 0.50
parse_object_pairsFunction · 0.50
serialize_sequenceFunction · 0.50
serialize_objectFunction · 0.50
modfFunction · 0.50

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected