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 · 0 comments
Open

Androidx DataStore generated support #3225

yschimke opened this issue Dec 29, 2024 · 0 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 = this@toOkioSerializer.decode(ByteString.EMPTY)

        override suspend fun readFrom(source: BufferedSource): T {
            try {
                return this@toOkioSerializer.decode(source)
            } catch (exception: IOException) {
                throw CorruptionException("Cannot read UserFavouriteGames proto.", exception)
            }
        }

        override suspend fun writeTo(t: T, sink: BufferedSink) {
            sink.write(t.encode())
        }
    }
}
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

1 participant