OkioSerializer
public interface OkioSerializer<T extends Object>
PreferencesSerializer |
Proto based serializer for Preferences. |
WebSerializer |
A Serializer that uses kotlinx.serialization.json to convert any @Serializable data class T to and from a byte stream using Okio. |
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 |
readFrom(@NonNull BufferedSource source)Unmarshal object from source. |
abstract void |
writeTo(@NonNull T t, @NonNull BufferedSink sink)Marshal object to a Sink. |
Public methods
getDefaultValue
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 input is corrupted and/or unparseable, e.g. InvalidProtocolBufferException when the type |
writeTo
abstract void writeTo(@NonNull T t, @NonNull BufferedSink sink)
Marshal object to a Sink.
| Parameters | |
|---|---|
@NonNull T t |
the data to write to output |
@NonNull BufferedSink sink |
the BufferedSink to serialize data to |