-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement i64/u64 using BigInt #21
Comments
BigInt used to be unsupported by wasm-bindgen itself, but searching among their issues, I found rustwasm/wasm-bindgen#2629 that finally implemented it recently. Among other things, it's added Those bindings have conversions from u64/i64 which you can use for deserialization: https://docs.rs/js-sys/0.3.55/js_sys/struct.BigInt.html#impl-From%3Ci64%3E I'm actually not sure how to do serialization yet - I don't see relevant APIs - but if you already figured out how to implement it as well, that's great. PR would be welcome (and welcome to Rust! 😀). |
Implemented in #24. |
Hi @RReverser, Refering to rustwasm/wasm-bindgen#2350 so as I a have an issue with u64 may I ask this works well using
prints
and this too
however this prints
what do I miss here please ? as both wasm-bindgen and serde-wasm-bindgen are supporting u64 to BigInt. Thanks |
@gRoussac See serde-wasm-bindgen docs, in particular:
It's not enabled by default because historically a lot of people expect i64/u64 to be fallibly converted to number (which is compatible with JSON as long as number is in 2^53 range) 🤷🏼♂️ |
@RReverser thank you my eyes did not pass the conversion table, I missed what was below, rtfm fatigue. So for the curious from
to
and now I also understand why maps were not objects too =) thank you very much |
At that point the variable also shouldn't be called JSON to avoid confusion :) (as BigInt is not a valid JSON value) |
Yes indeed as far as I understand it is still a JsValue but does not stringify as JSON on javascript side, the "json" var in my use case is actually a complex struct where the u64 is nested into. Now actually I am wondering if I use the correct approach as the doc says that if you don't need Maps/Sets etc then
and
are approx equivalent but last is JSON directly so I need to test now in my use case. Thanks again for your help. |
Well "directly" means it uses serde-json on Rust side to serialize to JSON, and then JS parses that string back. It might be sometimes faster and sometimes not, but at least in terms of size it tends to add more overhead. Measuring on your own app is the only way to know for sure. |
I tried to implement this feature myself, but I literally am using rust for the first time today.
Serializing the data is simple, by now it's implemented in serde. Sadly I have no idea how to implement the corresponding deserialization of it. Don't want to create a halfhearted PR tho...
The text was updated successfully, but these errors were encountered: