Overflow when encoding a big integer
When I encode a big integer(bigger than 2^31), it overflow and got a negative value in Node.js
This is because parseInt doesn't limit integer value in 32bit:
> parseInt(12345678901234)
12345678901234
Change the line:
var intVal = parseInt(val);
into:
var intVal = val | 0;
will solve this problem.
I can confirm that. That's a very unfortunate bug because it makes impossible to serialize timestamps thus making this package unusable for many programmers.
Simple reproducing case:
const PSON = require('pson')
const pson = new PSON.Pair()
const testData = {
ts: Date.now()
}
const buff = pson.encode(testData)
const testDecode = pson.decode(buff)
console.log(testData.ts, testDecode.ts)
// outputs 1531344982502 -1958342170
@nonphp You can try my incoming pr #10
Still not working
const PSON = require('pson') // 2.0.0
const pson = new PSON.ProgressivePair(['ts'])
const testData = { ts: 15313449825 }
const buff = pson.encode(testData)
const testDecode = pson.decode(buff)
console.log(testData.ts === testDecode.ts, testData.ts, testDecode.ts)
// outputs false, 15313449825 -1866419359
@Josema You can try my fork or modify that line manually and use patch-package to keep the changed line., this pr is still not merged.