Skip to content

Commit

Permalink
feat(wasm-api): add hexdump methods
Browse files Browse the repository at this point in the history
- add printHexdump()/hexdump()
  • Loading branch information
postspectacular committed Nov 3, 2022
1 parent 442a548 commit 95c91ed
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/wasm-api/src/bridge.ts
Expand Up @@ -557,4 +557,29 @@ export class WasmBridge<T extends WasmExports = WasmExports>
/** {@inheritDoc @thi.ng/api#INotify.notify} */
// @ts-ignore: mixin
notify(event: Event): void {}

printHexdump(addr: number, len: number) {
console.log(this.hexdump(addr, len).join("\n"));
}

hexdump(addr: number, len: number) {
const res = [];
while (len > 0) {
const row = [...this.u8.subarray(addr, addr + 16)];
res.push(
[
U32(addr),
...row.map(U8),
row
.map((x) =>
x >= 0x20 && x < 0x80 ? String.fromCharCode(x) : "."
)
.join(""),
].join(" ")
);
len -= 16;
addr += 16;
}
return res;
}
}

0 comments on commit 95c91ed

Please sign in to comment.