Closed listenaddress closed 4 years ago
Ok, the test case that I'm encoding only gets decoded in the tests. And when I encode it, I don't get the associated hex string.
Whoa. I wonder if my encoding tests have been running at all. Great find, I'm checking into it.
Ah, I think I've got it. 9223372036854775807
is in the decodeGood
list of tests, which are tests that decode correctly, but they don't round-trip because the canonical way of encoding is different than a valid way of encoding that number. I think everything is fine, but want to make sure you agree before closing this.
Thanks for taking a look!
What are you referencing by canonical and valid?
I am trying to match some cbor encoding written in Go, which produces 1b7fffffffffffffff
. Is that possible?
I guess you're asking for BigNumber integers and ECMAscript bigints to be encoded as normal integers, if they would fit. I'm open to adding an option for that, but since it's a breaking change as well as breaking round-tripping, I don't want to make it the default.
Fixed in version 5.0.2. Use the collapseBigIntegers
option.
console.log(cbor.encodeOne(0x7fffffffffffffffn, {
collapseBigIntegers: true
}).toString('hex'))
generates:
1b7fffffffffffffff
Awesome, thanks a lot Joe!
I haven't been able to recreate this encoding test case. Is there something I'm doing wrong?
Here's a repl.it.