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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions media/editor/dataInspectorProperties.tsx
@@ -1,3 +1,49 @@
/** 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) {
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 +112,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