VersionedCodec

class VersionedCodec<T : @Serializable Any>(file: Path, version: Int = 0, json: Json, serializer: KSerializer<T>, migration: Migration<T>, versionPath: Path = Path("$file.version"), tempPath: Path = uniqueTempFile(file), tempVersionPath: Path = uniqueTempFile(versionPath)) : Codec<T>

Constructors

Link copied to clipboard
constructor(file: Path, version: Int = 0, json: Json, serializer: KSerializer<T>, migration: Migration<T>, versionPath: Path = Path("$file.version"), tempPath: Path = uniqueTempFile(file), tempVersionPath: Path = uniqueTempFile(versionPath))

Functions

Link copied to clipboard
open suspend override fun decode(): T?

Decodes the file to a value. If the file does not exist, null is returned. If the file does not hold the current shape of T, the value is recovered through migration.

Link copied to clipboard
open suspend override fun encode(value: T?)

Encodes the given value to the file, along with the current version. If the value is null, both files are deleted. If the encoding fails, the temp files are deleted. On platforms where atomic move is not supported (e.g., Android 7 and below) this falls back to a non-atomic copy-and-delete; the transactional guarantee does not hold for that fallback path.