Serializer


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

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

TODO(b/151635324): consider changing InputStream to File.

Summary

Public functions

suspend T

Unmarshal object from stream.

android
suspend Unit
writeTo(t: T, output: OutputStream)

Marshal object to a stream.

android

Public properties

T

Value to return if there is no data on disk.

android

Public functions

readFrom

suspend fun readFrom(input: InputStream): T

Unmarshal object from stream.

Parameters
input: InputStream

the InputStream with the data to deserialize

writeTo

suspend fun writeTo(t: T, output: OutputStream): Unit

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

the OutputStream to serialize data to

Parameters
t: T

the data to write to output

Public properties

defaultValue

val defaultValue: T

Value to return if there is no data on disk.