BinaryFormat

SerialFormat that allows conversions to and from ByteArray via encodeToByteArray and decodeFromByteArray methods.

Not stable for inheritance

BinaryFormat interface is not stable for inheritance in 3rd party libraries, as new methods might be added to this interface or contracts of the existing methods can be changed.

It is safe to operate with instances of BinaryFormat and call its methods.

Properties

Link copied to clipboard

Contains all serializers registered by format user for Contextual and Polymorphic serialization.

Functions

Link copied to clipboard
abstract fun <T> decodeFromByteArray(deserializer: DeserializationStrategy<T>, bytes: ByteArray): T

Decodes and deserializes the given byte array to the value of type T using the given deserializer.

Link copied to clipboard

Decodes and deserializes the given byte array to the value of type T using deserializer retrieved from the reified type parameter.

Link copied to clipboard

Decodes byte array from the given hex string and the decodes and deserializes it to the value of type T, delegating it to the BinaryFormat.

Link copied to clipboard
abstract fun <T> encodeToByteArray(serializer: SerializationStrategy<T>, value: T): ByteArray

Serializes and encodes the given value to byte array using the given serializer.

Link copied to clipboard

Serializes and encodes the given value to byte array using serializer retrieved from the reified type parameter.

Link copied to clipboard
inline fun <T> BinaryFormat.encodeToHexString(value: T): String

Serializes and encodes the given value to byte array, delegating it to the BinaryFormat, and then encodes resulting bytes to hex string.