(tag: u32, ptr: *const u8, len: u32)
| 241 | // Bootstrap encoder: classifies (tag, bytes) into a Val handle; returns 0 on Invalid. |
| 242 | #[unsafe(no_mangle)] |
| 243 | pub 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)] |
nothing calls this directly
no test coverage detected