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

Function host_edge_encode

compiler/src/main/abi_bridge.rs:243–259  ·  view source on GitHub ↗
(tag: u32, ptr: *const u8, len: u32)

Source from the content-addressed store, hash-verified

241// Bootstrap encoder: classifies (tag, bytes) into a Val handle; returns 0 on Invalid.
242#[unsafe(no_mangle)]
243pub unsafe extern "C" fn host_edge_encode(tag: u32, ptr: *const u8, len: u32) -> u32 {
244 // Alloc in the live VM; 0 when outside run() or OOM.
245 fn alloc_and_put(obj: HeapObj) -> u32 {
246 match with_vm(|vm| vm.heap.alloc(obj).ok()).flatten() {
247 Some(val) => put_val(val),
248 None => 0,
249 }
250 }
251 let bytes = unsafe { safe_bytes(ptr, len) };
252 match classify_encode(tag, bytes) {
253 EncodeRequest::Direct(bits) => put_val(Val(bits)),
254 EncodeRequest::AllocStr(s) => alloc_and_put(HeapObj::Str(s.to_string())),
255 EncodeRequest::AllocBytes(b) => alloc_and_put(HeapObj::Bytes(b.to_vec())),
256 EncodeRequest::AllocLongInt(i) => alloc_and_put(HeapObj::LongInt(i)),
257 EncodeRequest::Invalid => 0,
258 }
259}
260
261// Bootstrap decoder: writes tag to `*out_tag`, bytes to `dst[..dst_max]`.
262#[unsafe(no_mangle)]

Callers

nothing calls this directly

Calls 6

safe_bytesFunction · 0.85
classify_encodeFunction · 0.85
put_valFunction · 0.85
ValClass · 0.85
alloc_and_putFunction · 0.85
BytesClass · 0.85

Tested by

no test coverage detected