VersionedBinarySerializer

abstract class VersionedBinarySerializer<T : Any>(currentVersion: UByte) : BinarySerializer<T>

A BinarySerializer for a versioned format of T, supporting nulls. Every value is prefixed with an unsigned byte, where 0 indicates a null value and any other value indicates a non-null value in a specific version. A VersionedBinarySerializer can only write data in the current version, but can also read data serialized in previous versions.

Parameters

currentVersion

The current version of the format, i.e. the unsigned byte that will be written on serialization.

Constructors

Link copied to clipboard
constructor(currentVersion: UByte)

Functions

Link copied to clipboard
open override fun copy(obj: T?): T?

Creates a deep copy of obj.

Link copied to clipboard
abstract fun copyNonNull(obj: T): T

Creates a deep copy of the given non-null obj.

Link copied to clipboard
override fun read(reader: ByteReader): T?

Reads a value of type T? from reader.

Link copied to clipboard
fun <T : Any> BinarySerializer<T>.read(bytes: ByteArray, strict: Boolean = true): T?

Reads a value of type T from bytes.

Link copied to clipboard
abstract fun readVersioned(version: UByte, reader: ByteReader): T

Reads a non-null value of type T from reader in the specified version.

Link copied to clipboard
override fun write(obj: T?, writer: ByteWriter)

Writes the given obj of type T? to writer.

Link copied to clipboard

Writes the given obj of type T to a ByteArray.

Link copied to clipboard
abstract fun writeVersioned(obj: T, writer: ByteWriter)

Writes the given non-null obj of type T to writer in the current version format.