-
-
Save pavan5208/fc631e994d99a57d5a047cc9d0fca0ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sample.android_sample_preference_datastore.proto | |
import androidx.datastore.core.CorruptionException | |
import androidx.datastore.core.Serializer | |
import com.google.protobuf.InvalidProtocolBufferException | |
import com.sample.android_sample_preference_datastore.UserStore | |
import java.io.InputStream | |
import java.io.OutputStream | |
object UserStoreSerializer : Serializer<UserStore> { | |
override val defaultValue: UserStore = UserStore.getDefaultInstance() | |
override suspend fun readFrom(input: InputStream): UserStore { | |
try { | |
return UserStore.parseFrom(input) | |
} catch (exception: InvalidProtocolBufferException) { | |
throw CorruptionException("Cannot read proto.", exception) | |
} | |
} | |
override suspend fun writeTo(t: UserStore, output: OutputStream) = t.writeTo(output) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment