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.

interface BinaryFormat : SerialFormat

Functions

decodeFromByteArray
Link copied to clipboard
common

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

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

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

abstract fun <T> encodeToByteArray(serializer: SerializationStrategy<T>, value: T): ByteArray
equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
toString
Link copied to clipboard
common
open override fun toString(): String

Properties

serializersModule
Link copied to clipboard
common

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

The same module should be exposed in the format's Encoder and Decoder.

abstract override val serializersModule: SerializersModule

Extensions

decodeFromByteArray
Link copied to clipboard
common

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

inline fun <T> BinaryFormat.decodeFromByteArray(bytes: ByteArray): T
decodeFromHexString
Link copied to clipboard
common

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.

This method is a counterpart to encodeToHexString

fun <T> BinaryFormat.decodeFromHexString(deserializer: DeserializationStrategy<T>, hex: String): T
inline fun <T> BinaryFormat.decodeFromHexString(hex: String): T
encodeToByteArray
Link copied to clipboard
common

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

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

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

Hex representation does not interfere with serialization and encoding process of the format and only applies transformation to the resulting array. It is recommended to use for debugging and testing purposes.

fun <T> BinaryFormat.encodeToHexString(serializer: SerializationStrategy<T>, value: T): String
inline fun <T> BinaryFormat.encodeToHexString(value: T): String