| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Hi @gfx, is this PR something you would consider adding to the library? |
Sorry, something went wrong.
|
We'd also love it if this could be merged. The current ExtensionCodec example isn't really usable since it encodes large integers as strings, which would require special casing on the decoding side (which, in our case, isn't in JS). |
Sorry, something went wrong.
|
Hi @gfx, could you please approve the workflow run for this PR so github actions will run? |
Sorry, something went wrong.
|
Hi. Thank you for the pull request, and sorry for my delayed response. I'd like to include the BigInt support in the next major release (v3.0). Please wait for my review & decision. |
Sorry, something went wrong.
|
Any update? |
Sorry, something went wrong.
|
Added another solution: useBigInt64 Please use it. |
Sorry, something went wrong.
|
⚠️ Please install the Codecov ReportAttention: Patch coverage is 97.43590% with 2 lines in your changes missing coverage. Please review.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #211 +/- ##
==========================================
- Coverage 98.14% 98.05% -0.10%
==========================================
Files 16 16
Lines 969 1026 +57
Branches 206 225 +19
==========================================
+ Hits 951 1006 +55
- Misses 18 20 +2 ☔ View full report in Codecov by Sentry. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This PR adds native support for JavaScript BigInts.
I didn't want to cause a breaking change in any way, so I've introduced a few different decoding options that essentially allow library users to opt into this feature. Additionally, since no BigInts are returned by this library by default, everything else should remain functional in environments where BigInt is not supported.
Encoding
Similar to Numbers, BigInts are encoded using the smallest possible MessagePack int type. The added benefit of encoding a BigInt is that integers larger than Number.MAX_SAFE_INTEGER can be encoded with the correct precision.
If you attempt to encode a BigInt larger than the maximum uint64 value or smaller than the minimum int64 value, an error will be thrown, since MessagePack does not support larger integer types.
Decoding
Decoding BigInts is more nuanced. I believe there is no single correct way to do this, since consumers of this library will want different behavior depending on their use cases. For example, some may never want to see a BigInt from this library, some may only want to see BigInts if the value being decoded cannot fit into a Number, and some may want to always receive BigInts for consistency.
Instead of choosing just a single way to decoding integers, I've offered the following possibilities, which can be specified with the new DecodeOptions.intMode option:
For backwards compatibility, IntMode.UNSAFE_NUMBER is the default value for decoding. As a result, there should be no change in behavior for users who do not specify this option.
At Algorand, we've had success adopting a similar approach for JSON integer decoding: algorand/js-algorand-sdk#260
Tests
New tests have been added to ensure the new functionality works as intended. Additionally, I've enabled the bignum tests from msgpack-test-js.
Feedback is appreciated, please let me know if there are any questions or suggested changes!
Closes #115