Let's think about the following situation.
The Go routine creates a byte array where packs a Uint64 number 5577006791947779410
in 8 bytes Big Endian [77, 101, 130, 33, 7, 252, 253, 82]
.
In JavaScript code I receive these bytes as Uint8Array
. We know that JavaScript doesn't currently support Uint64 as safe numeric type and cannot perform bitwise operations on integers larger than 32 bits, so things like buf[0] << 56
will never work.
So what is the process of decoding these bytes directly to numeric string "5577006791947779410"
?
P.S. I know there are plenty of libraries for working with big integers in JavaScript, but generally they are huge and provide lots of mathematical operations, which I don't need here. I am looking for a simple modern straightforward solution for just decoding BE-packed Uint64 and Int64 bytes to numeric string. Do you have anything in mind?
uint64
. What modifications should I need to do make in order this to work withint64
as well? I have created a playground here: jsfiddle.net/wcqLj1qg. – Disembarrass