Skip to content
Open
Changes from all 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
25 changes: 18 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@

function parse() {
var type = dataView.getUint8(offset);
var value, length;
var value, length, ms32b, ls32b;
switch (type) {
// nil
case 0xc0:
Expand Down Expand Up @@ -347,10 +347,12 @@
return value;
// uint64
case 0xcf:
// value = buffer.readUInt64BE(offset + 1);
log(offset, 9, "uint64 marker - cannot parse uint64 to javascript, setting to Infinity");
ms32b = dataView.getUint32(offset + 1);
ls32b = dataView.getUint32(offset + 5);
value = (BigInt(ms32b) << 32n) + BigInt(ls32b);
log(offset, 9, "uint64 value " + value);
offset += 9;
return Infinity;
return value;
// int 8
case 0xd0:
value = dataView.getInt8(offset + 1);
Expand All @@ -371,9 +373,12 @@
return value;
// int 64
case 0xd3:
log(offset, 9, "int64 marker - cannot parse uint64 to javascript, setting to Infinity");
ms32b = dataView.getUint32(offset + 1);
ls32b = dataView.getUint32(offset + 5);
value = BigInt.asIntN(64, (BigInt(ms32b) << 32n) + BigInt(ls32b));
log(offset, 9, "int64 value " + value);
offset += 9;
return Infinity;
return value;
// map 16
case 0xde:
length = dataView.getUint16(offset + 1);
Expand Down Expand Up @@ -534,14 +539,20 @@
var byteVal = dataView.getUint8(i);
displayByte(byteVal, i);
}
jsonobj.innerHTML = JSON.stringify(decode(dataView), null, 2);
jsonobj.innerHTML = JSON.stringify(decode(dataView), bigIntJSONReplacer, 2);
indent();
} catch (e) {
errlog("Error parsing input: " + e.message);
e.stack && errlog(e.stack);
}
}

function bigIntJSONReplacer(key, value) {
return typeof value === 'bigint'
? value.toString()
: value;
}

function getQSParams() {
return window.location.search
.substr(1)
Expand Down