Serializer
Kotlin
|Java
interface Serializer<T>
androidx.datastore.core.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 methods | |
---|---|
abstract T |
readFrom(input: InputStream) Unmarshal object from stream. |
abstract Unit |
writeTo(t: T, output: OutputStream) Marshal object to a stream. |
Properties | |
---|---|
abstract T |
Value to return if there is no data on disk. |
Public methods
readFrom
abstract fun readFrom(input: InputStream): T
Unmarshal object from stream.
Parameters | |
---|---|
input: InputStream | the InputStream with the data to deserialize |
writeTo
abstract fun writeTo(
t: T,
output: OutputStream
): Unit
Marshal object to a stream. Closing the provided OutputStream is a no-op.
Parameters | |
---|---|
t: T | the data to write to output |
Properties
defaultValue
abstract val defaultValue: T
Value to return if there is no data on disk.