-
-
Save muthuraj57/687ef7063eb5e7a93c7bd461c6984718 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
object UserPreferencesSerializer : Serializer<UserPreferences> { | |
override val defaultValue: UserPreferences = UserPreferences() | |
override suspend fun readFrom(input: InputStream): UserPreferences { | |
try { | |
return UserPreferences.ADAPTER.decode(input) | |
} catch (exception: IOException) { | |
throw CorruptionException("Cannot read proto.", exception) | |
} | |
} | |
override suspend fun writeTo( | |
t: UserPreferences, | |
output: OutputStream) = t.adapter.encode(output, t) | |
} | |
val Context.sserPreferencesDataStore: DataStore<UserPreferences> by dataStore( | |
fileName = "user_preferences.pb", | |
serializer = UserPreferencesSerializer | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment