corda / net.corda.core.serialization / SerializedBytes

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.

Constructors

<init>

SerializedBytes(bytes: ByteArray)

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

Properties

hash

val hash: SecureHash

Inherited Properties

bytes

val bytes: ByteArray

The bytes are always cloned so that this object becomes immutable. This has been done to prevent tampering with entities such as net.corda.core.crypto.SecureHash and net.corda.core.contracts.PrivacySalt, as well as preserve the integrity of our hash constants net.corda.core.crypto.SecureHash.zeroHash and net.corda.core.crypto.SecureHash.allOnesHash.

Companion Object Functions

from

fun <T : Any> from(obj: T, serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): SerializedBytes<T>

Serializes the given object and returns a SerializedBytes wrapper for it. An alias for Any.serialize intended to make the calling smoother for Java users.

Extension Properties

isZero

val OpaqueBytes.isZero: Boolean

Extension Functions

contextLogger

fun Any.contextLogger(): <ERROR CLASS>

When called from a companion object, returns the logger for the enclosing class.

deserialize

fun <T : Any> SerializedBytes<T>.deserialize(serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): T

Convenience extension method for deserializing SerializedBytes with type matching, utilising the defaults.

deserializeWithCompatibleContext

fun <T : Any> ByteSequence.deserializeWithCompatibleContext(serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): ObjectWithCompatibleContext<T>

Additionally returns SerializationContext which was used for encoding. It might be helpful to know SerializationContext to use the same encoding in the reply.

hashAs

fun OpaqueBytes.hashAs(algorithm: String): SecureHash

Compute the algorithm hash for the contents of the OpaqueBytes.

sha256

fun OpaqueBytes.sha256(): SHA256

Compute the SHA-256 hash for the contents of the OpaqueBytes.