Title: Add BigInt support by jasonpaulos · Pull Request #211 · msgpack/msgpack-javascript · GitHub
Open Graph Title: Add BigInt support by jasonpaulos · Pull Request #211 · msgpack/msgpack-javascript
X Title: Add BigInt support by jasonpaulos · Pull Request #211 · msgpack/msgpack-javascript
Description: 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: IntMode.UNSAFE_NUMBER: Always returns the value as a number. Be aware that there will be a loss of precision if the value is outside the range of Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER. IntMode.SAFE_NUMBER: Always returns the value as a number, but throws an error if the value is outside of the range of Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER. IntMode.MIXED: Returns all values inside the range of Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER as numbers and all values outside that range as bigints. IntMode.BIGINT: Always returns the value as a bigint, even if it is small enough to safely fit in a number. 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
Open Graph Description: 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 u...
X Description: 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 l...
Opengraph URL: https://github.com/msgpack/msgpack-javascript/pull/211
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7308fef1-2d09-b5e2-cc08-9142cf38e756 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CB0A:3D0DAC:1C1D89C:28FD347:6A563818 |
| html-safe-nonce | fe3de8149d8fb0f9b639181f4254d7f21d6eed35d3c0a66c7a9ceafbec78b9ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjBBOjNEMERBQzoxQzFEODlDOjI4RkQzNDc6NkE1NjM4MTgiLCJ2aXNpdG9yX2lkIjoiNjUxNzg4OTcyMjc2MDk2ODIxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4465bffdcc863da5ceb64ffd98a9efd739c37c80373878898548f0e639c7f603 |
| hovercard-subject-tag | pull_request:928197951 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/msgpack/msgpack-javascript/pull/211/files |
| twitter:image | https://avatars.githubusercontent.com/u/5856867?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/5856867?s=400&v=4 |
| og:image:alt | 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 u... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d78ea552aac0685ca5f006d44f88166cbbf3bb96843f8da0c5a2c0b9908430b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/msgpack/msgpack-javascript git https://github.com/msgpack/msgpack-javascript.git |
| octolytics-dimension-user_id | 198264 |
| octolytics-dimension-user_login | msgpack |
| octolytics-dimension-repository_id | 2761854 |
| octolytics-dimension-repository_nwo | msgpack/msgpack-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2761854 |
| octolytics-dimension-repository_network_root_nwo | msgpack/msgpack-javascript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423b2fb76ac2b90de5ab599b7a76a0d2b2c83f24 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width