Skip to content
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

Streaming bindings #399

Merged
merged 17 commits into from
Jan 8, 2024
Merged

Streaming bindings #399

merged 17 commits into from
Jan 8, 2024

Conversation

neekolas
Copy link
Contributor

@neekolas neekolas commented Jan 5, 2024

Summary

Message streaming requires the caller to implement a class in Swift/Kotlin that meets the FfiMessageCallback interface defined in the UDL file. The on_message function will be called once per message.

Notes

I tried very hard to figure out a way to wrap a Stream type into something FFI friendly. The main issue is that our group.stream() method keeps a reference to self for the life of the stream, which in turn has a lifetimed reference to Client. This is required so that we can actually decrypt messages. The problem is that Uniffi doesn't play nicely with lifetimed references. We can't store a MlsGroup on any sort of FFI friendly struct, and so the reference always gets dropped before the stream is done. This makes the compiler unhappy.

Maybe someone smarter than me can figure it out (I've tried every permutation of boxes/arcs/mutexes I can think of), but I have to admit the callback interface might actually be easier in the end. At least we aren't exposing any sort of exotic types to Swift/Kotlin. The memory management should be simpler since the stream never leaves Rust-land.

@neekolas neekolas marked this pull request as ready for review January 8, 2024 23:39
@neekolas neekolas requested a review from a team January 8, 2024 23:39
Copy link
Contributor

@nplasterer nplasterer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍 I like the evolution of Intro, Invite, Welcome. 😄

@neekolas neekolas merged commit a461b3d into main Jan 8, 2024
7 checks passed
@neekolas neekolas deleted the nm/streaming-bindings branch January 8, 2024 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants