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 methods

@NonNull Preferences

Value to return if there is no data on disk.

@NonNull Preferences

Unmarshal object from source.

void

Marshal object to a Sink.

Public fields

INSTANCE

Added in 1.1.0
public @NonNull PreferencesSerializer INSTANCE

Public methods

getDefaultValue

Added in 1.1.0
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

Added in 1.1.0
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