(exps, handle, expectedTag)
| 31 | } |
| 32 | |
| 33 | function 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 | |
| 56 | const decodeStr = (exps, h) => TD.decode(decodeBytes(exps, h, TAG_BYTES)); |
| 57 | const decodeInt = (exps, h) => { |
no outgoing calls
no test coverage detected