Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display in data inspector ULEB128 and SLEB128 #488

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions media/editor/dataInspectorProperties.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
/** Reads a ULEB128 at offset 0 from the buffer. */
const getULEB128 = (arrayBuffer: ArrayBuffer) => {
const buf = new Uint8Array(arrayBuffer);

let result = 0n;
let shift = 0n;
let index = 0;
try {
while (true) {
if (shift > 128n) {
return "";
}
const byte: bigint = BigInt(buf[index++]);
result |= (byte & 0x7Fn) << shift;
if ((0x80n & byte) === 0n) {
connor4312 marked this conversation as resolved.
Show resolved Hide resolved
return result;
}
shift += 7n;
}
} catch {
jogo- marked this conversation as resolved.
Show resolved Hide resolved
return "";
}
};

/** Reads a SLEB128 at offset 0 from the buffer. */
const getSLEB128 = (arrayBuffer: ArrayBuffer) => {
jogo- marked this conversation as resolved.
Show resolved Hide resolved
const buf = new Uint8Array(arrayBuffer);

let result = 0n;
let shift = 0n;
let index = 0;
try {
while (true) {
const byte: bigint = BigInt(buf[index++]);
result |= (byte & 0x7Fn) << shift;
shift += 7n;
if ((0x80n & byte) === 0n) {
if (shift < 128n && (byte & 0x40n) !== 0n) {
result |= (~0n << shift);
return result;
}
return result;
}
}
} catch {
return "";
}
};

/** Reads a uint24 at offset 0 from the buffer. */
const getUint24 = (arrayBuffer: ArrayBuffer, le: boolean) => {
const buf = new Uint8Array(arrayBuffer);
Expand Down Expand Up @@ -66,6 +115,9 @@ const inspectTypesBuilder: IInspectableType[] = [
{ label: "uint64", minBytes: 8, convert: (dv, le) => dv.getBigUint64(0, le).toString() },
{ label: "int64", minBytes: 8, convert: (dv, le) => dv.getBigInt64(0, le).toString() },

{ label: "ULEB128", minBytes: 1, convert: dv => getULEB128(dv.buffer).toString() },
{ label: "SLEB128", minBytes: 1, convert: dv => getSLEB128(dv.buffer).toString() },

{
label: "float16",
minBytes: 2,
Expand Down