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

Function decodeBytes

runtime/src/rt.js:33–54  ·  view source on GitHub ↗
(exps, handle, expectedTag)

Source from the content-addressed store, hash-verified

31}
32
33function decodeBytes(exps, handle, expectedTag) {
34 const tagPtr = exps.wasm_alloc(4);
35 let cap = 256;
36 let dstPtr = exps.wasm_alloc(cap);
37 let n = exps.host_edge_decode(handle, tagPtr, dstPtr, cap);
38 if (n < 0) {
39 const needed = -n;
40 exps.wasm_free(dstPtr, cap);
41 cap = needed;
42 dstPtr = exps.wasm_alloc(cap);
43 n = exps.host_edge_decode(handle, tagPtr, dstPtr, cap);
44 }
45 const tag = new DataView(exps.memory.buffer).getUint32(tagPtr, true);
46 exps.wasm_free(tagPtr, 4);
47 if (tag !== expectedTag) {
48 exps.wasm_free(dstPtr, cap);
49 throw new Error(`expected tag ${expectedTag}, got ${tag}`);
50 }
51 const out = new Uint8Array(exps.memory.buffer, dstPtr, n).slice();
52 exps.wasm_free(dstPtr, cap);
53 return out;
54}
55
56const decodeStr = (exps, h) => TD.decode(decodeBytes(exps, h, TAG_BYTES));
57const decodeInt = (exps, h) => {

Callers 4

decodeStrFunction · 0.85
decodeIntFunction · 0.85
decodeBoolFunction · 0.85
decodeFloatFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected