PreferencesSerializer
public static class PreferencesSerializer implements OkioSerializer
Proto based serializer for Preferences. Can be used to manually create DataStore using the DataStoreFactory#create function.
Summary
Public fields |
|
|---|---|
@NonNull PreferencesSerializer |
Public methods |
|
|---|---|
@NonNull Preferences |
Value to return if there is no data on disk. |
@NonNull Preferences |
readFrom(@NonNull BufferedSource source)Unmarshal object from source. |
void |
writeTo(@NonNull Preferences t, @NonNull BufferedSink sink)Marshal object to a Sink. |
Public fields
Public methods
getDefaultValue
public @NonNull Preferences getDefaultValue()
Value to return if there is no data on disk.
readFrom
public @NonNull Preferences readFrom(@NonNull BufferedSource source)
Unmarshal object from source.
| Parameters | |
|---|---|
@NonNull BufferedSource source |
the BufferedSource 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
public void writeTo(@NonNull Preferences t, @NonNull BufferedSink sink)
Marshal object to a Sink.
| Parameters | |
|---|---|
@NonNull Preferences t |
the data to write to output |
@NonNull BufferedSink sink |
the BufferedSink to serialize data to |