ssbc / bipf

Binary json codec optimized for in-place access
MIT License
48 stars 9 forks source link

ERR_OUT_OF_RANGE #15

Closed luandro closed 2 years ago

luandro commented 2 years ago

I've playing with sending LoRa packets over SSB, using ssb-db2. I'm getting this error related to the values in the LoRa packet which I'm translating to json as they are, Ints:

Received onTextPacket
NEW TEXT PACKET {
  packet: {
    from: 4066789380,
    to: 4294967295,
    channel: 0,
    payloadVariant: { oneofKind: 'decoded', decoded: [Object] },
    id: 3731283723,
    rxTime: 1635936589,
    rxSnr: 5.75,
    hopLimit: 3,
    wantAck: false,
    priority: 0,
    rxRssi: 0
  },
  data: 'Salve6'
}
Error sending message RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received 3731283723
    at new NodeError (node:internal/errors:371:5)
    at checkInt (node:internal/buffer:72:11)
    at writeU_Int32LE (node:internal/buffer:692:3)
    at Buffer.writeInt32LE (node:internal/buffer:861:10)
    at Array.Integer (/home/dev/node_modules/bipf/index.js:28:12)
    at encode (/home/dev/node_modules/bipf/index.js:201:24)
    at Array.Object (/home/dev/node_modules/bipf/index.js:47:10)
    at encode (/home/dev/node_modules/bipf/index.js:201:24)
    at Array.Object (/home/dev/node_modules/bipf/index.js:47:10)
    at encode (/home/dev/node_modules/bipf/index.js:201:24) {
  code: 'ERR_OUT_OF_RANGE'
}

Is turning them to strings the best solution?

arj03 commented 2 years ago

Hello @luandro

Yes the ints in bipf are signed so can't hold 3731283723. Besides a string, you can maybe see if it works if they are double (little endian 64 bit float). Try with 3731283723.0 and see if that works.

luandro commented 2 years ago

Yup, that worked @arj03 thanks! Added .toFixed(2) to all the ints.