PreferencesFileSerializer



Proto based serializer for Preferences. Can be used to manually create DataStore using the DataStoreFactory#create function.

Summary

Public functions

open suspend Preferences

Unmarshal object from stream.

android
open suspend Unit

Marshal object to a stream.

android

Public properties

open Preferences

Value to return if there is no data on disk.

android

Public functions

readFrom

open suspend fun readFrom(input: InputStream): Preferences

Unmarshal object from stream.

Parameters
input: InputStream

the InputStream with the data to deserialize

Throws
androidx.datastore.core.CorruptionException

if the data from input is corrupted and/or unparseable, e.g. InvalidProtocolBufferException when the type T is a protobuf message and it is corrupted. Other unrecoverable IOException from the file system should not be thrown as CorruptionException.

writeTo

open suspend fun writeTo(t: Preferences, output: OutputStream): Unit

Marshal object to a stream. Closing the provided OutputStream is a no-op.

Parameters
t: Preferences

the data to write to output

output: OutputStream

the OutputStream to serialize data to

Public properties

defaultValue

open val defaultValuePreferences

Value to return if there is no data on disk.