mozilla / application-services

Firefox Application Services
https://mozilla.github.io/application-services/
Other
620 stars 227 forks source link

Figure out to integrate protobuf into mozilla-central #2891

Closed eoger closed 4 years ago

eoger commented 4 years ago

Some fxa methods output protocol buffers, and some of them even take protobufs as input. We need to figure out how to unpack/pack protobuf messages in the gecko world. Some ideas:

┆Issue is synchronized with this Jira Task ┆Epic: Choose What to Sync accepted and declined engines ┆Sprint: Backlog

rfk commented 4 years ago

Unpack/Pack types at the rust bridge level, and use JSON to talk to JS

Does this have to be JSON, or could we create a live Object that gets shared back to JS via the XPCOM bindings? I don't know enough about the nitty-gritty details of the bridge layer.

eoger commented 4 years ago

Unpack/Pack types at the rust bridge level, and use JSON to talk to JS

Does this have to be JSON, or could we create a live Object that gets shared back to JS via the XPCOM bindings? I don't know enough about the nitty-gritty details of the bridge layer.

Yeah that's a good idea, maybe? We should explore our solutions here!

eoger commented 4 years ago

I realized that we don't need this since we don't even use the ffi 😅, however the original issue could still be re-phrased as "Figure out how to pass complex values back from Rust to JS". After talking to @linacambridge, seems like there's 2 methods: JSON stringify or return a nsIPropertyBag. I went with the first option!

linabutler commented 4 years ago

Adding a bit more from our Slack discussion for context! 😁 There are a few ways to pass complex objects between native and JS code:

Based on that, I agree, JSON strings are the way to go!

mhammond commented 4 years ago

Thanks for that write up!

Based on that, I agree, JSON strings are the way to go!

I got the impression from some earlier comments from @thomcc that there are protobuf issues for our existing components for Android and iOS.

What's our strategy here going forward? Should we back away from protobufs everywhere? If not, should we develop some docs with guidance?

linabutler commented 4 years ago

Oh, interesting, I didn't realize there were issues in our existing components!

One other thing that makes JSON convenient to use on Desktop is, we're talking to JavaScript, so native JSON parsing is 1) available, and 2) going to be easier to use and faster than any other format, like protobuf. But that's not the case with Kotlin and Swift.

Whatever we decide, I think developing some docs with guidance around this makes a lot of sense! One of my Q2 goals is to document how to land Rust code in Desktop, and this would be great to add as a "how should I pass stuff back and forth?" section.