From df087313f644512b2562b387311d0c62082cbf8b Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Fri, 25 Jun 2021 17:39:30 -0700 Subject: [PATCH 1/2] add support for uint64 and int64 types --- index.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index fced9ad..5b191d1 100644 --- a/index.html +++ b/index.html @@ -274,7 +274,7 @@ function parse() { var type = dataView.getUint8(offset); - var value, length; + var value, length, ms32b, ls32b; switch (type) { // nil case 0xc0: @@ -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); @@ -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); From 6402ffc07162251180241013220530f9808650da Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Thu, 1 Jul 2021 10:21:55 -0700 Subject: [PATCH 2/2] add replacer function for JSON.stringify --- index.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 5b191d1..85cb3c0 100644 --- a/index.html +++ b/index.html @@ -539,7 +539,7 @@ 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); @@ -547,6 +547,12 @@ } } + function bigIntJSONReplacer(key, value) { + return typeof value === 'bigint' + ? value.toString() + : value; + } + function getQSParams() { return window.location.search .substr(1)