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

Androidx DataStore generated support #3225

Open
yschimke opened this issue Dec 29, 2024 · 2 comments
Open

Androidx DataStore generated support #3225

yschimke opened this issue Dec 29, 2024 · 2 comments

Comments

@yschimke
Copy link

Is there any plans for integration with Androidx DataStore? Or does Androidx provide this somewhere?

There are some nuances with https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-core-okio/src/commonMain/kotlin/androidx/datastore/core/okio/OkioSerializer.kt?q=OkioSerializer

That would be good to handle once. Something like

fun <T: Message<T, Nothing>> ProtoAdapter<T>.toOkioSerializer(): OkioSerializer<T> {
    return object : OkioSerializer<T> {
        override val defaultValue: T = [email protected](ByteString.EMPTY)

        override suspend fun readFrom(source: BufferedSource): T {
            try {
                return [email protected](source)
            } catch (exception: IOException) {
                throw CorruptionException("Cannot read UserFavouriteGames proto.", exception)
            }
        }

        override suspend fun writeTo(t: T, sink: BufferedSink) {
            sink.write(t.encode())
        }
    }
}
@oldergod
Copy link
Member

oldergod commented Jan 6, 2025

The answer is I don't know so probably no.
Could this be added to your project and work as is otherwise?

@yschimke
Copy link
Author

yschimke commented Jan 6, 2025

Yeah, it's working fine locally. Just feels like anyone using Wire and DataStore will have to write exactly the same adapter.

Feel free to close.

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

No branches or pull requests

2 participants