square / square/wire

Androidx DataStore generated support

Open
#3,225 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AndroidX's datastore-core-okio OkioSerializer.kt implementation linked in the issue, then compare it with the proposed ProtoAdapter extension. Check the default-value, readFrom, and writeTo behavior shown in the example; done means Wire provides the requested AndroidX DataStore integration while handling those noted nuances.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.