From e79da0ebae82fc626aa506d79df831d1c4c66b05 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Mon, 21 Aug 2017 11:12:59 +0100 Subject: [PATCH] Ensure that the serialisation scheme is initialised as soon as the class is loaded. (#27) --- .../enclaves/txverify/KryoSerializationScheme.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/verify-enclave/src/main/kotlin/com/r3/enclaves/txverify/KryoSerializationScheme.kt b/verify-enclave/src/main/kotlin/com/r3/enclaves/txverify/KryoSerializationScheme.kt index c1c8b3d1fc..257ef5c6b0 100644 --- a/verify-enclave/src/main/kotlin/com/r3/enclaves/txverify/KryoSerializationScheme.kt +++ b/verify-enclave/src/main/kotlin/com/r3/enclaves/txverify/KryoSerializationScheme.kt @@ -1,10 +1,13 @@ package com.r3.enclaves.txverify import net.corda.core.serialization.SerializationContext +import net.corda.core.serialization.SerializationDefaults import net.corda.core.serialization.SerializationFactory import net.corda.core.utilities.ByteSequence import net.corda.nodeapi.internal.serialization.AbstractKryoSerializationScheme +import net.corda.nodeapi.internal.serialization.KRYO_P2P_CONTEXT import net.corda.nodeapi.internal.serialization.KryoHeaderV0_1 +import net.corda.nodeapi.internal.serialization.SerializationFactoryImpl @Suppress("UNUSED") private class KryoVerifierSerializationScheme(serializationFactory: SerializationFactory) : AbstractKryoSerializationScheme(serializationFactory) { @@ -14,4 +17,16 @@ private class KryoVerifierSerializationScheme(serializationFactory: Serializatio override fun rpcClientKryoPool(context: SerializationContext) = throw UnsupportedOperationException() override fun rpcServerKryoPool(context: SerializationContext) = throw UnsupportedOperationException() + + /* + * Registers the serialisation scheme as soon as the class is loaded into the JVM. + */ + private companion object { + init { + SerializationDefaults.SERIALIZATION_FACTORY = SerializationFactoryImpl().apply { + registerScheme(KryoVerifierSerializationScheme(this)) + } + SerializationDefaults.P2P_CONTEXT = KRYO_P2P_CONTEXT + } + } }