core.serialization

Package core.serialization

Types

ImmutableClassSerializer class ImmutableClassSerializer<T : Any>

Serializes properties and deserializes by using the constructor. This assumes that all backed properties are set via the constructor and the class is immutable.

OpaqueBytes open class OpaqueBytes

A simple class that wraps a byte array and makes the equals/hashCode/toString methods work as you actually expect. In an ideal JVM this would be a value type and be completely overhead free. Project Valhalla is adding such functionality to Java, but it wont arrive for a few years yet

SerializedBytes class SerializedBytes<T : Any> : OpaqueBytes

A type safe wrapper around a byte array that contains a serialised object. You can call SerializedBytes.deserialize to get the original object back.

Extensions for External Classes

kotlin.ByteArray

Properties

THREAD_LOCAL_KRYO val THREAD_LOCAL_KRYO: <ERROR CLASS>

Serialization utilities, using the Kryo framework with a custom serialiser for immutable data classes and a dead simple, totally non-extensible binary (sub)format.

Functions

createKryo fun createKryo(k: <ERROR CLASS> = Kryo()): <ERROR CLASS>
deserialize fun <T : Any> OpaqueBytes.deserialize(kryo: <ERROR CLASS> = THREAD_LOCAL_KRYO.get(), includeClassName: Boolean = false): T
fun SerializedBytes<WireTransaction>.deserialize(): WireTransaction
fun <T : Any> SerializedBytes<T>.deserialize(): T
serialize fun <T : Any> T.serialize(kryo: <ERROR CLASS> = THREAD_LOCAL_KRYO.get(), includeClassName: Boolean = false): SerializedBytes<T>

Can be called on any object to convert it to a byte array (wrapped by SerializedBytes), regardless of whether the type is marked as serializable or was designed for it (so be careful)