mirror of
https://github.com/corda/corda.git
synced 2025-01-18 18:56:28 +00:00
Replaced class Kryo2 with extension method on Kryo
This commit is contained in:
parent
bba0a4a55d
commit
9561013b65
@ -190,7 +190,7 @@ inline fun <T> Kryo.useClassLoader(cl: ClassLoader, body: () -> T) : T {
|
||||
}
|
||||
}
|
||||
|
||||
fun createKryo(k: Kryo = core.serialization.Kryo2()): Kryo {
|
||||
fun createKryo(k: Kryo = Kryo()): Kryo {
|
||||
return k.apply {
|
||||
// Allow any class to be deserialized (this is insecure but for prototyping we don't care)
|
||||
isRegistrationRequired = false
|
||||
@ -228,7 +228,7 @@ fun createKryo(k: Kryo = core.serialization.Kryo2()): Kryo {
|
||||
var inputs = kryo.readClassAndObject( input ) as List<StateRef>
|
||||
var attachments = kryo.readClassAndObject( input ) as List<SecureHash>
|
||||
|
||||
val attachmentStorage = (kryo as? core.serialization.Kryo2)?.attachmentStorage
|
||||
val attachmentStorage = kryo.attachmentStorage
|
||||
|
||||
// .filterNotNull in order for TwoPartyTradeProtocolTests.checkDependenciesOfSaleAssetAreResolved test to run
|
||||
val classLoader = core.node.AttachmentsClassLoader.create( attachments.map { attachmentStorage?.openAttachment(it) }.filterNotNull() )
|
||||
@ -264,11 +264,10 @@ fun createKryo(k: Kryo = core.serialization.Kryo2()): Kryo {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends Kryo with a field for passing attachmentStorage to serializer for WireTransaction
|
||||
*
|
||||
* TODO: Think of better solution, or at least better name
|
||||
*/
|
||||
class Kryo2() : Kryo() {
|
||||
var attachmentStorage: AttachmentStorage? = null
|
||||
}
|
||||
val ATTACHMENT_STORAGE = "ATTACHMENT_STORAGE"
|
||||
|
||||
var Kryo.attachmentStorage: AttachmentStorage?
|
||||
get() = this.context.get(ATTACHMENT_STORAGE, null) as AttachmentStorage?
|
||||
set(value) {
|
||||
this.context.put(ATTACHMENT_STORAGE, value)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import contracts.DUMMY_PROGRAM_ID
|
||||
import contracts.DummyContract
|
||||
import core.*
|
||||
import core.crypto.SecureHash
|
||||
import core.serialization.attachmentStorage
|
||||
import core.serialization.createKryo
|
||||
import core.serialization.deserialize
|
||||
import core.serialization.serialize
|
||||
@ -215,7 +216,7 @@ class ClassLoaderTests {
|
||||
|
||||
var storage = MockAttachmentStorage()
|
||||
|
||||
var kryo = createKryo() as core.serialization.Kryo2
|
||||
var kryo = createKryo()
|
||||
|
||||
// todo - think about better way to push attachmentStorage down to serializer
|
||||
kryo.attachmentStorage = storage
|
||||
@ -228,7 +229,7 @@ class ClassLoaderTests {
|
||||
|
||||
val bytes = wireTransaction.serialize(kryo)
|
||||
|
||||
kryo = createKryo() as core.serialization.Kryo2
|
||||
kryo = createKryo()
|
||||
|
||||
// use empty attachmentStorage
|
||||
kryo.attachmentStorage = storage
|
||||
@ -252,7 +253,7 @@ class ClassLoaderTests {
|
||||
|
||||
var storage = MockAttachmentStorage()
|
||||
|
||||
var kryo = createKryo() as core.serialization.Kryo2
|
||||
var kryo = createKryo()
|
||||
|
||||
// todo - think about better way to push attachmentStorage down to serializer
|
||||
kryo.attachmentStorage = storage
|
||||
@ -265,7 +266,7 @@ class ClassLoaderTests {
|
||||
|
||||
val bytes = wireTransaction.serialize(kryo)
|
||||
|
||||
kryo = createKryo() as core.serialization.Kryo2
|
||||
kryo = createKryo()
|
||||
// use empty attachmentStorage
|
||||
kryo.attachmentStorage = MockAttachmentStorage()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user