mapbox / pbf

A low-level, lightweight protocol buffers implementation in JavaScript.
BSD 3-Clause "New" or "Revised" License
796 stars 106 forks source link

added support for js_type using bigint #120

Closed UlysseM closed 4 years ago

UlysseM commented 4 years ago

Writing this as a proof of concept to get some feedback. (my take on #44)

This approach is intended to be backward compatible with existing system. When dealing with int64* family, it checks whether the option jstype is set. If set to JS_STRING, it returns a string and parses a string. If set to JS_NUMBER, it returns a BigInt and parses a BigInt.

API wise, if we don't want to introduce BigInt in the index.js (to maintain compatibility with older browser without the need to ship polyfills), we could:

Let me know if you're ok with this approach / feature, so that I can polish it / write tests.

UlysseM commented 4 years ago

A bit too complex after further thoughts. I added support for js_type at compile time without the needs of bigint.

It doesn't solve number in the order of 2^53, but support for it could be added later.