mirror of
https://github.com/corda/corda.git
synced 2025-06-18 15:18:16 +00:00
CORDA-973 Compression support for serialization (#2473)
* Serialization magic is now 7 bytes * Introduce encoding property and whitelist
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package net.corda.core.serialization
|
||||
|
||||
import net.corda.core.DoNotImplement
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import net.corda.core.crypto.sha256
|
||||
import net.corda.core.serialization.internal.effectiveSerializationEnv
|
||||
@ -99,14 +100,22 @@ abstract class SerializationFactory {
|
||||
}
|
||||
}
|
||||
typealias SerializationMagic = ByteSequence
|
||||
@DoNotImplement
|
||||
interface SerializationEncoding
|
||||
|
||||
/**
|
||||
* Parameters to serialization and deserialization.
|
||||
*/
|
||||
@DoNotImplement
|
||||
interface SerializationContext {
|
||||
/**
|
||||
* When serializing, use the format this header sequence represents.
|
||||
*/
|
||||
val preferredSerializationVersion: SerializationMagic
|
||||
/**
|
||||
* If non-null, apply this encoding (typically compression) when serializing.
|
||||
*/
|
||||
val encoding: SerializationEncoding?
|
||||
/**
|
||||
* The class loader to use for deserialization.
|
||||
*/
|
||||
@ -115,6 +124,10 @@ interface SerializationContext {
|
||||
* A whitelist that contains (mostly for security purposes) which classes can be serialized and deserialized.
|
||||
*/
|
||||
val whitelist: ClassWhitelist
|
||||
/**
|
||||
* A whitelist that determines (mostly for security purposes) whether a particular encoding may be used when deserializing.
|
||||
*/
|
||||
val encodingWhitelist: EncodingWhitelist
|
||||
/**
|
||||
* A map of any addition properties specific to the particular use case.
|
||||
*/
|
||||
@ -161,6 +174,11 @@ interface SerializationContext {
|
||||
*/
|
||||
fun withPreferredSerializationVersion(magic: SerializationMagic): SerializationContext
|
||||
|
||||
/**
|
||||
* A shallow copy of this context but with the given (possibly null) encoding.
|
||||
*/
|
||||
fun withEncoding(encoding: SerializationEncoding?): SerializationContext
|
||||
|
||||
/**
|
||||
* The use case that we are serializing for, since it influences the implementations chosen.
|
||||
*/
|
||||
@ -232,3 +250,8 @@ class SerializedBytes<T : Any>(bytes: ByteArray) : OpaqueBytes(bytes) {
|
||||
interface ClassWhitelist {
|
||||
fun hasListed(type: Class<*>): Boolean
|
||||
}
|
||||
|
||||
@DoNotImplement
|
||||
interface EncodingWhitelist {
|
||||
fun acceptEncoding(encoding: SerializationEncoding): Boolean
|
||||
}
|
||||
|
Reference in New Issue
Block a user