Skip to content

Androidx DataStore generated support #3225

Open
@yschimke

Description

@yschimke

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())
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions