OkioSerializer


public interface OkioSerializer<T extends Object>
Known direct subclasses

The OkioSerializer determines the on-disk format and API for accessing it.

The type T MUST be immutable. Mutable types will result in broken DataStore functionality.

Summary

Public methods

abstract @NonNull T

Value to return if there is no data on disk.

abstract @NonNull T

Unmarshal object from source.

abstract void
writeTo(@NonNull T t, @NonNull BufferedSink sink)

Marshal object to a Sink.

Public methods

getDefaultValue

Added in 1.1.0
abstract @NonNull T getDefaultValue()

Value to return if there is no data on disk.

readFrom

abstract @NonNull T 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 source is corrupted and/or unparseable, e.g. InvalidProtocolBufferException when the type T is a protobuf message and it is corrupted. Other unrecoverable androidx.datastore.core.IOException from the file system should not be thrown as androidx.datastore.core.CorruptionException.

writeTo

Added in 1.1.0
abstract void writeTo(@NonNull T t, @NonNull BufferedSink sink)

Marshal object to a Sink.