diff --git a/rd-kt/rd-core/src/main/kotlin/com/jetbrains/rd/util/hash/IncrementalHash.kt b/rd-kt/rd-core/src/main/kotlin/com/jetbrains/rd/util/hash/IncrementalHash.kt index ad321a49d..9f63e84e7 100644 --- a/rd-kt/rd-core/src/main/kotlin/com/jetbrains/rd/util/hash/IncrementalHash.kt +++ b/rd-kt/rd-core/src/main/kotlin/com/jetbrains/rd/util/hash/IncrementalHash.kt @@ -4,4 +4,10 @@ class IncrementalHash64(r: Long = 0) { fun mix(mix: String?) = IncrementalHash64(mix?.fold(result) { acc, c -> acc*31 + c.toInt()} ?: result) fun mix(collection : Iterable, map : (T) -> String) = collection.fold(this) {acc, elt -> acc.mix(map(elt))} val result: Long = r -} \ No newline at end of file +} + + +//PLEASE DO NOT CHANGE IT!!! IT'S EXACTLY THE SAME ON C# SIDE +fun String?.getPlatformIndependentHash(initial: Long = 19L) : Long = this?.fold(initial) { acc, c -> acc*31 + c.toInt()} ?:0 +fun Int.getPlatformIndependentHash(initial: Long = 19L) : Long = initial*31 + (this + 1) +fun Long.getPlatformIndependentHash(initial: Long = 19L) : Long = initial*31 + (this + 1) \ No newline at end of file diff --git a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/FrameworkMarshallers.kt b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/FrameworkMarshallers.kt index d7187b282..b6893f9c7 100644 --- a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/FrameworkMarshallers.kt +++ b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/FrameworkMarshallers.kt @@ -3,6 +3,7 @@ package com.jetbrains.rd.framework import com.jetbrains.rd.framework.impl.RdSecureString import com.jetbrains.rd.util.* import kotlin.reflect.* +import kotlin.time.Duration open class UniversalMarshaller( override val _type: KClass<*>, @@ -27,13 +28,18 @@ open class DelegatedMarshaller(marshaller: IMarshaller create(crossinline reader: (AbstractBuffer) -> T, crossinline writer: (AbstractBuffer, T) -> Unit, predefinedId: Int? = null): UniversalMarshaller { - return UniversalMarshaller(T::class, { _, stream -> reader(stream) }, { _, stream, v -> writer(stream, v) }, predefinedId) + @Deprecated("Use an overload without inlining", ReplaceWith("create(T::class, reader, writer, predefinedId)", "com.jetbrains.rd.framework.FrameworkMarshallers.create")) + inline fun create(noinline reader: (AbstractBuffer) -> T, noinline writer: (AbstractBuffer, T) -> Unit, predefinedId: Int? = null): UniversalMarshaller { + return create(T::class, reader, writer, predefinedId) } - + + fun create(clazz: KClass, reader: (AbstractBuffer) -> T, writer: (AbstractBuffer, T) -> Unit, predefinedId: Int? = null): UniversalMarshaller { + return UniversalMarshaller(clazz, { _, stream -> reader(stream) }, { _, stream, v -> writer(stream, v) }, predefinedId) + } + inline fun > enum(): UniversalMarshaller { - return create({ it.readEnum() }, { stream, x -> stream.writeEnum(x) }) + return create(T::class, { it.readEnum() }, { stream, x -> stream.writeEnum(x) } ) } inline fun > enumSet(): UniversalMarshaller> { @@ -50,21 +56,21 @@ object FrameworkMarshallers { } - val Int8 : IMarshaller = create(AbstractBuffer::readByte, AbstractBuffer::writeByte, 1) - val Int16: IMarshaller = create(AbstractBuffer::readShort, AbstractBuffer::writeShort, 2) - val Int32: IMarshaller = create(AbstractBuffer::readInt, AbstractBuffer::writeInt, 3) - val Int64: IMarshaller = create(AbstractBuffer::readLong, AbstractBuffer::writeLong, 4) + val Int8 : IMarshaller = create(kotlin.Byte::class, AbstractBuffer::readByte, AbstractBuffer::writeByte, 1) + val Int16: IMarshaller = create(kotlin.Short::class, AbstractBuffer::readShort, AbstractBuffer::writeShort, 2) + val Int32: IMarshaller = create(kotlin.Int::class, AbstractBuffer::readInt, AbstractBuffer::writeInt, 3) + val Int64: IMarshaller = create(kotlin.Long::class, AbstractBuffer::readLong, AbstractBuffer::writeLong, 4) - val Float: IMarshaller = create(AbstractBuffer::readFloat, AbstractBuffer::writeFloat, 5) - val Double: IMarshaller = create(AbstractBuffer::readDouble, AbstractBuffer::writeDouble, 6) - val Char: IMarshaller = create(AbstractBuffer::readChar, AbstractBuffer::writeChar, 7) - val Bool: IMarshaller = create(AbstractBuffer::readBoolean, AbstractBuffer::writeBoolean, 8) + val Float: IMarshaller = create(kotlin.Float::class, AbstractBuffer::readFloat, AbstractBuffer::writeFloat, 5) + val Double: IMarshaller = create(kotlin.Double::class, AbstractBuffer::readDouble, AbstractBuffer::writeDouble, 6) + val Char: IMarshaller = create(kotlin.Char::class, AbstractBuffer::readChar, AbstractBuffer::writeChar, 7) + val Bool: IMarshaller = create(Boolean::class, AbstractBuffer::readBoolean, AbstractBuffer::writeBoolean, 8) //empty - val Void: IMarshaller = create({ }, { _, _ -> }, 9) + val Void: IMarshaller = create(Unit::class, { }, { _, _ -> }, 9) //normal string - val String: UniversalMarshaller = create(AbstractBuffer::readString, AbstractBuffer::writeString, 10) + val String: UniversalMarshaller = create(kotlin.String::class, AbstractBuffer::readString, AbstractBuffer::writeString, 10) //aliases val Byte = Int8 @@ -74,48 +80,48 @@ object FrameworkMarshallers { //jvm-based - val Guid: UniversalMarshaller = create({ it.readUuid() }, AbstractBuffer::writeUuid, 11) - val DateTime: UniversalMarshaller = create(AbstractBuffer::readDateTime, AbstractBuffer::writeDateTime, 12) - val Uri: UniversalMarshaller = create({ it.readUri() }, AbstractBuffer::writeUri, 13) - var TimeSpan: UniversalMarshaller = create(AbstractBuffer::readTimeSpan, AbstractBuffer::writeTimeSpan, 14) + val Guid: UniversalMarshaller = create(java.util.UUID::class, { it.readUuid() }, AbstractBuffer::writeUuid, 11) + val DateTime: UniversalMarshaller = create(java.util.Date::class, AbstractBuffer::readDateTime, AbstractBuffer::writeDateTime, 12) + val Uri: UniversalMarshaller = create(java.net.URI::class, { it.readUri() }, AbstractBuffer::writeUri, 13) + var TimeSpan: UniversalMarshaller = create(Duration::class, AbstractBuffer::readTimeSpan, AbstractBuffer::writeTimeSpan, 14) //rdId - val RdId: IMarshaller = create(AbstractBuffer::readRdId, AbstractBuffer::writeRdId, 15) + val RdId: IMarshaller = create(com.jetbrains.rd.framework.RdId::class, AbstractBuffer::readRdId, AbstractBuffer::writeRdId, 15) //string for passwords - val SecureString: IMarshaller = create({ RdSecureString(it.readString()) }, { buf, str -> buf.writeString(str.contents) }, 16) + val SecureString: IMarshaller = create(RdSecureString::class, { RdSecureString(it.readString()) }, { buf, str -> buf.writeString(str.contents) }, 16) //arrays - val ByteArray: UniversalMarshaller = create(AbstractBuffer::readByteArray, AbstractBuffer::writeByteArray, 31) - val ShortArray: UniversalMarshaller = create(AbstractBuffer::readShortArray, AbstractBuffer::writeShortArray, 32) - val IntArray: UniversalMarshaller = create(AbstractBuffer::readIntArray, AbstractBuffer::writeIntArray, 33) - val LongArray: UniversalMarshaller = create(AbstractBuffer::readLongArray, AbstractBuffer::writeLongArray, 34) + val ByteArray: UniversalMarshaller = create(kotlin.ByteArray::class, AbstractBuffer::readByteArray, AbstractBuffer::writeByteArray, 31) + val ShortArray: UniversalMarshaller = create(kotlin.ShortArray::class, AbstractBuffer::readShortArray, AbstractBuffer::writeShortArray, 32) + val IntArray: UniversalMarshaller = create(kotlin.IntArray::class, AbstractBuffer::readIntArray, AbstractBuffer::writeIntArray, 33) + val LongArray: UniversalMarshaller = create(kotlin.LongArray::class, AbstractBuffer::readLongArray, AbstractBuffer::writeLongArray, 34) - val FloatArray: UniversalMarshaller = create(AbstractBuffer::readFloatArray, AbstractBuffer::writeFloatArray, 35) - val DoubleArray: UniversalMarshaller = create(AbstractBuffer::readDoubleArray, AbstractBuffer::writeDoubleArray, 36) + val FloatArray: UniversalMarshaller = create(kotlin.FloatArray::class, AbstractBuffer::readFloatArray, AbstractBuffer::writeFloatArray, 35) + val DoubleArray: UniversalMarshaller = create(kotlin.DoubleArray::class, AbstractBuffer::readDoubleArray, AbstractBuffer::writeDoubleArray, 36) - val CharArray: UniversalMarshaller = create(AbstractBuffer::readCharArray, AbstractBuffer::writeCharArray, 37) - val BooleanArray: UniversalMarshaller = create(AbstractBuffer::readBooleanArray, AbstractBuffer::writeBooleanArray, 38) + val CharArray: UniversalMarshaller = create(kotlin.CharArray::class, AbstractBuffer::readCharArray, AbstractBuffer::writeCharArray, 37) + val BooleanArray: UniversalMarshaller = create(kotlin.BooleanArray::class, AbstractBuffer::readBooleanArray, AbstractBuffer::writeBooleanArray, 38) //unsigned @ExperimentalUnsignedTypes - val UByte : IMarshaller = create(AbstractBuffer::readUByte, AbstractBuffer::writeUByte, 41) + val UByte : IMarshaller = create(kotlin.UByte::class, AbstractBuffer::readUByte, AbstractBuffer::writeUByte, 41) @ExperimentalUnsignedTypes - val UShort: IMarshaller = create(AbstractBuffer::readUShort, AbstractBuffer::writeUShort, 42) + val UShort: IMarshaller = create(kotlin.UShort::class, AbstractBuffer::readUShort, AbstractBuffer::writeUShort, 42) @ExperimentalUnsignedTypes - val UInt: IMarshaller = create(AbstractBuffer::readUInt, AbstractBuffer::writeUInt, 43) + val UInt: IMarshaller = create(kotlin.UInt::class, AbstractBuffer::readUInt, AbstractBuffer::writeUInt, 43) @ExperimentalUnsignedTypes - val ULong: IMarshaller = create(AbstractBuffer::readULong, AbstractBuffer::writeULong, 44) + val ULong: IMarshaller = create(kotlin.ULong::class, AbstractBuffer::readULong, AbstractBuffer::writeULong, 44) @ExperimentalUnsignedTypes - val UByteArray: UniversalMarshaller = create(AbstractBuffer::readUByteArray, AbstractBuffer::writeUByteArray, 45) + val UByteArray: UniversalMarshaller = create(kotlin.UByteArray::class, AbstractBuffer::readUByteArray, AbstractBuffer::writeUByteArray, 45) @ExperimentalUnsignedTypes - val UShortArray: UniversalMarshaller = create(AbstractBuffer::readUShortArray, AbstractBuffer::writeUShortArray, 46) + val UShortArray: UniversalMarshaller = create(kotlin.UShortArray::class, AbstractBuffer::readUShortArray, AbstractBuffer::writeUShortArray, 46) @ExperimentalUnsignedTypes - val UIntArray: UniversalMarshaller = create(AbstractBuffer::readUIntArray, AbstractBuffer::writeUIntArray, 47) + val UIntArray: UniversalMarshaller = create(kotlin.UIntArray::class, AbstractBuffer::readUIntArray, AbstractBuffer::writeUIntArray, 47) @ExperimentalUnsignedTypes - val ULongArray: UniversalMarshaller = create(AbstractBuffer::readULongArray, AbstractBuffer::writeULongArray, 48) + val ULongArray: UniversalMarshaller = create(kotlin.ULongArray::class, AbstractBuffer::readULongArray, AbstractBuffer::writeULongArray, 48) fun registerIn(serializers: ISerializers) { serializers.register(Int8) diff --git a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Identities.kt b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Identities.kt index be9e92eae..47d5ed50b 100644 --- a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Identities.kt +++ b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Identities.kt @@ -2,6 +2,7 @@ package com.jetbrains.rd.framework import com.jetbrains.rd.util.AtomicInteger +import com.jetbrains.rd.util.hash.getPlatformIndependentHash import com.jetbrains.rd.util.string.condstr enum class IdKind { @@ -10,15 +11,19 @@ enum class IdKind { } //PLEASE DO NOT CHANGE IT!!! IT'S EXACTLY THE SAME ON C# SIDE -fun String?.getPlatformIndependentHash(initial: Long = 19L) : Long = this?.fold(initial) { acc, c -> acc*31 + c.toInt()} ?:0 -fun Int.getPlatformIndependentHash(initial: Long = 19L) : Long = initial*31 + (this + 1) -fun Long.getPlatformIndependentHash(initial: Long = 19L) : Long = initial*31 + (this + 1) +@Deprecated("Api moved to com.jetbrains.rd.util.hash", ReplaceWith("getPlatformIndependentHash(initial)","com.jetbrains.rd.util.hash.getPlatformIndependentHash")) +fun String?.getPlatformIndependentHash(initial: Long = 19L) : Long = getPlatformIndependentHash(initial) +@Deprecated("Api moved to com.jetbrains.rd.util.hash", ReplaceWith("getPlatformIndependentHash(initial)","com.jetbrains.rd.util.hash.getPlatformIndependentHash")) +fun Int.getPlatformIndependentHash(initial: Long = 19L) : Long = getPlatformIndependentHash(initial) +@Deprecated("Api moved to com.jetbrains.rd.util.hash", ReplaceWith("getPlatformIndependentHash(initial)","com.jetbrains.rd.util.hash.getPlatformIndependentHash")) +fun Long.getPlatformIndependentHash(initial: Long = 19L) : Long = getPlatformIndependentHash(initial) /** * An identifier of the object that participates in the object graph. */ -data class RdId(val hash: Long) { +@JvmInline +value class RdId(val hash: Long) { companion object { val Null : RdId = RdId( 0) diff --git a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Interfaces.kt b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Interfaces.kt index 31c5080f5..577a793f4 100644 --- a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Interfaces.kt +++ b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Interfaces.kt @@ -6,8 +6,8 @@ import com.jetbrains.rd.framework.impl.ProtocolContexts import com.jetbrains.rd.util.lifetime.Lifetime import com.jetbrains.rd.util.reactive.* import com.jetbrains.rd.util.string.RName -import java.rmi.NotBoundException import kotlin.reflect.KClass +import kotlin.reflect.jvm.jvmName /** * A node in a graph of entities that can be synchronized with its remote copy over a network or a similar connection. @@ -97,6 +97,32 @@ interface IMarshaller : ISerializer { get() = RdId(_type.simpleName.getPlatformIndependentHash()) } +val IMarshaller<*>.fqn: String get() { + return if (this is LazyCompanionMarshaller) this.fgn + else _type.qualifiedName ?: _type.jvmName +} + +class LazyCompanionMarshaller( + override val id: RdId, + val classLoader: ClassLoader, + val fqn: String +) : IMarshaller { + private val lazy = lazy(LazyThreadSafetyMode.PUBLICATION) { + Class.forName(fgn, true, classLoader).getDeclaredField("Companion").get(null) as IMarshaller + } + + override val _type: KClass<*> + get() = lazy.value._type + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): T { + return lazy.value.read(ctx, buffer) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: T) { + lazy.value.write(ctx, buffer, value) + } +} + interface IAbstractDeclaration { fun readUnknownInstance(ctx: SerializationCtx, buffer: AbstractBuffer, unknownId: RdId, size: Int): T } diff --git a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/MarshallerUtils.kt b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/MarshallerUtils.kt index 2a1f058e9..544be6892 100644 --- a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/MarshallerUtils.kt +++ b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/MarshallerUtils.kt @@ -1,5 +1,6 @@ package com.jetbrains.rd.framework +import com.jetbrains.rd.framework.FrameworkMarshallers.create import com.jetbrains.rd.framework.base.IRdWireable import com.jetbrains.rd.framework.impl.RdSignal import com.jetbrains.rd.util.string.RName @@ -9,7 +10,7 @@ object RNameMarshaller { val isEmpty = buffer.readBoolean() if (isEmpty) return RName.Empty - + val rootName = buffer.readString() var last = buffer.readBoolean() var rName = RName(rootName) @@ -41,8 +42,7 @@ object RNameMarshaller { } internal fun IRdDynamic.createExtSignal(): RdSignal { - val marshaller = FrameworkMarshallers.create( - { buffer -> + val marshaller = create(ExtCreationInfo::class, { buffer -> val rName = RNameMarshaller.read(buffer) val rdId = buffer.readNullable { buffer.readRdId() } val hash = buffer.readLong() diff --git a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Serializers.kt b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Serializers.kt index 83e2b90f5..8d7350301 100644 --- a/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Serializers.kt +++ b/rd-kt/rd-framework/src/main/kotlin/com/jetbrains/rd/framework/Serializers.kt @@ -3,8 +3,11 @@ package com.jetbrains.rd.framework import com.jetbrains.rd.framework.base.ISerializersOwner import com.jetbrains.rd.framework.impl.RdSecureString import com.jetbrains.rd.util.* +import com.jetbrains.rd.util.hash.getPlatformIndependentHash import com.jetbrains.rd.util.lifetime.Lifetime +import java.util.concurrent.TimeUnit import kotlin.reflect.KClass +import kotlin.reflect.jvm.jvmName import kotlin.time.Duration import kotlin.time.DurationUnit import kotlin.time.toDuration @@ -33,9 +36,8 @@ class Serializers : ISerializers { - val types = hashMapOf>() - val writers = hashMapOf, Pair Unit>>() - val marshallers = hashMapOf>() + private val writers = ConcurrentHashMap, IMarshaller<*>>() + private val marshallers = ConcurrentHashMap>() init { backgroundRegistrar.invokeOrQueue { @@ -50,19 +52,15 @@ class Serializers : ISerializers { } val id = serializer.id - val t = serializer._type - - Protocol.initializationLogger.trace { "Registering type ${t.simpleName}, id = $id" } - - val existing = types[id] + val existing = marshallers[id] if (existing != null) { - require(existing == t) { "Can't register ${t.simpleName} with id: $id, already registered: ${existing.simpleName}" } - } else { - types[id] = t + require(existing.fqn == serializer.fqn) { "Can't register ${serializer.fqn} with id: $id, already registered: ${serializer.fqn}" } + } else { + Protocol.initializationLogger.trace { "Registering type ${serializer.fqn}, id = $id" } + marshallers[id] = serializer + if (serializer !is LazyCompanionMarshaller) + writers[serializer._type] = serializer } - - marshallers[id] = serializer - writers[t] = Pair(id, serializer::write) as Pair Unit> } override fun get(id: RdId): IMarshaller<*>? { @@ -102,22 +100,34 @@ class Serializers : ISerializers { ?: throw IllegalStateException("Non-null object expected") } + private fun getWriter(clazz: KClass): IMarshaller { + val marshaller = writers.getOrPut(clazz) { + val id = RdId(clazz.simpleName.getPlatformIndependentHash()) + marshallers[id] ?: cantFindWriter(clazz) + } + + return marshaller as? IMarshaller ?: cantFindWriter(clazz) + } + + private fun cantFindWriter(clazz: KClass): Nothing { + throw IllegalStateException("Can't find writer by class: ${clazz}. $notRegisteredErrorMessage") + } + override fun writePolymorphic(ctx: SerializationCtx, stream: AbstractBuffer, value: T) { backgroundRegistrar.flush() - val (id, writer) = writers[value::class] - ?: throw IllegalStateException("Can't find writer by class: ${value::class}. $notRegisteredErrorMessage") + val serializer = getWriter(value::class) if (value is IUnknownInstance) { value.unknownId.write(stream) } else { - id.write(stream) + serializer.id.write(stream) } val lengthTagPosition = stream.position stream.writeInt(0) val objectStartPosition = stream.position - writer(ctx, stream, value) + serializer.write(ctx, stream, value) val objectEndPosition = stream.position stream.position = lengthTagPosition stream.writeInt(objectEndPosition - objectStartPosition) diff --git a/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/RdGen.kt b/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/RdGen.kt index 72170c3e5..4490e8bd9 100644 --- a/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/RdGen.kt +++ b/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/RdGen.kt @@ -22,7 +22,7 @@ class RdGen : Kli() { /** * Moving this field forward you trigger rebuild even if inputs and output of generator hasn't changed. */ - const val version = "1.12" + const val version = "1.13" /** * File to store all information for incremental work diff --git a/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/kotlin/Kotlin11Generator.kt b/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/kotlin/Kotlin11Generator.kt index 1d9d1620b..e120b724a 100644 --- a/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/kotlin/Kotlin11Generator.kt +++ b/rd-kt/rd-gen/src/main/kotlin/com/jetbrains/rd/generator/nova/kotlin/Kotlin11Generator.kt @@ -9,6 +9,7 @@ import com.jetbrains.rd.generator.nova.util.decapitalizeInvariant import com.jetbrains.rd.generator.nova.util.joinToOptString import com.jetbrains.rd.util.eol import com.jetbrains.rd.util.hash.IncrementalHash64 +import com.jetbrains.rd.util.hash.getPlatformIndependentHash import com.jetbrains.rd.util.string.Eol import com.jetbrains.rd.util.string.PrettyPrinter import com.jetbrains.rd.util.string.condstr @@ -519,6 +520,7 @@ open class Kotlin11Generator( println() block("companion object : IMarshaller<${decl.name}>") { + "override val _type: KClass<${decl.name}> = ${decl.name}::class" + + "override val id: RdId get() = RdId(${decl.name.getPlatformIndependentHash()})" println() readerTrait(decl) println() @@ -543,6 +545,7 @@ open class Kotlin11Generator( println() block("companion object : IMarshaller<${decl.name}>, IAbstractDeclaration<${decl.name}>") { +"override val _type: KClass<${decl.name}> = ${decl.name}::class" + +"override val id: RdId get() = RdId(${decl.name.getPlatformIndependentHash()})" println() readerTrait(decl) println() @@ -609,8 +612,17 @@ open class Kotlin11Generator( protected fun PrettyPrinter.registerSerializersTrait(decl: Toplevel, types: List) { block("override fun registerSerializersCore(serializers: ISerializers) ") { + var first = true types.filter { !it.isAbstract }.filterIsInstance().println { - "serializers.register(${it.serializerRef(decl, true)})" + if (it is Declaration && it.getSetting(Intrinsic) == null) { + if (first) { + +"val classLoader = javaClass.classLoader" + first = false + } + "serializers.register(LazyCompanionMarshaller(RdId(${it.name.getPlatformIndependentHash()}), classLoader, \"${it.namespace}.${it.name}\"))" + } else { + "serializers.register(${it.serializerRef(decl, true)})" + } } if (decl is Root) { @@ -1087,10 +1099,21 @@ open class Kotlin11Generator( docComment(it.documentation) + it.name } println() - block("companion object") { + block("companion object : IMarshaller<${decl.substitutedName(decl)}>") { +"val marshaller = FrameworkMarshallers.enum${decl.setOrEmpty}<${decl.name}>()" println() constantTrait(decl) + println() + + "override val _type: KClass<${decl.name}> = ${decl.name}::class" + + "override val id: RdId get() = RdId(${decl.name.getPlatformIndependentHash()})" + println() + block("override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ${decl.substitutedName(decl)}") { + +"return marshaller.read(ctx, buffer)" + } + println() + block("override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: ${decl.substitutedName(decl)}) ") { + +"marshaller.write(ctx, buffer, value)" + } } } } diff --git a/rd-kt/rd-gen/src/test/resources/testData/callGeneratedCode/asis/CallGeneratedCodeRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/callGeneratedCode/asis/CallGeneratedCodeRoot.kt index 36f2caf7c..1c307719d 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/callGeneratedCode/asis/CallGeneratedCodeRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/callGeneratedCode/asis/CallGeneratedCodeRoot.kt @@ -25,9 +25,10 @@ class CallGeneratedCodeRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(Editor) - serializers.register(Es.marshaller) - serializers.register(Abc) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(18933576544), classLoader, "call.generated.code.root.Editor")) + serializers.register(LazyCompanionMarshaller(RdId(20513), classLoader, "call.generated.code.root.Es")) + serializers.register(LazyCompanionMarshaller(RdId(631631), classLoader, "call.generated.code.root.Abc")) CallGeneratedCodeRoot.register(serializers) } @@ -72,6 +73,7 @@ class Abc ( companion object : IMarshaller { override val _type: KClass = Abc::class + override val id: RdId get() = RdId(631631) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Abc { @@ -127,6 +129,7 @@ class Editor private constructor( companion object : IMarshaller { override val _type: KClass = Editor::class + override val id: RdId get() = RdId(18933576544) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Editor { @@ -213,8 +216,19 @@ enum class Es { b, c; - companion object { + companion object : IMarshaller> { val marshaller = FrameworkMarshallers.enumSet() + + override val _type: KClass = Es::class + override val id: RdId get() = RdId(20513) + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): EnumSet { + return marshaller.read(ctx, buffer) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: EnumSet) { + marshaller.write(ctx, buffer, value) + } } } diff --git a/rd-kt/rd-gen/src/test/resources/testData/callGeneratedCode/reversed/CallGeneratedCodeRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/callGeneratedCode/reversed/CallGeneratedCodeRoot.kt index 36f2caf7c..1c307719d 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/callGeneratedCode/reversed/CallGeneratedCodeRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/callGeneratedCode/reversed/CallGeneratedCodeRoot.kt @@ -25,9 +25,10 @@ class CallGeneratedCodeRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(Editor) - serializers.register(Es.marshaller) - serializers.register(Abc) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(18933576544), classLoader, "call.generated.code.root.Editor")) + serializers.register(LazyCompanionMarshaller(RdId(20513), classLoader, "call.generated.code.root.Es")) + serializers.register(LazyCompanionMarshaller(RdId(631631), classLoader, "call.generated.code.root.Abc")) CallGeneratedCodeRoot.register(serializers) } @@ -72,6 +73,7 @@ class Abc ( companion object : IMarshaller { override val _type: KClass = Abc::class + override val id: RdId get() = RdId(631631) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Abc { @@ -127,6 +129,7 @@ class Editor private constructor( companion object : IMarshaller { override val _type: KClass = Editor::class + override val id: RdId get() = RdId(18933576544) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Editor { @@ -213,8 +216,19 @@ enum class Es { b, c; - companion object { + companion object : IMarshaller> { val marshaller = FrameworkMarshallers.enumSet() + + override val _type: KClass = Es::class + override val id: RdId get() = RdId(20513) + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): EnumSet { + return marshaller.read(ctx, buffer) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: EnumSet) { + marshaller.write(ctx, buffer, value) + } } } diff --git a/rd-kt/rd-gen/src/test/resources/testData/defaultNlsValues/asis/DefaultNlsValuesRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/defaultNlsValues/asis/DefaultNlsValuesRoot.kt index 84c582426..eb3f20946 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/defaultNlsValues/asis/DefaultNlsValuesRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/defaultNlsValues/asis/DefaultNlsValuesRoot.kt @@ -25,7 +25,8 @@ class DefaultNlsValuesRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(ClassModel) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(17439278522805508), classLoader, "DefaultNlsValuesRoot.ClassModel")) DefaultNlsValuesRoot.register(serializers) } @@ -72,6 +73,7 @@ class ClassModel private constructor( companion object : IMarshaller { override val _type: KClass = ClassModel::class + override val id: RdId get() = RdId(17439278522805508) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ClassModel { diff --git a/rd-kt/rd-gen/src/test/resources/testData/defaultNlsValues/reversed/DefaultNlsValuesRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/defaultNlsValues/reversed/DefaultNlsValuesRoot.kt index 84c582426..eb3f20946 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/defaultNlsValues/reversed/DefaultNlsValuesRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/defaultNlsValues/reversed/DefaultNlsValuesRoot.kt @@ -25,7 +25,8 @@ class DefaultNlsValuesRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(ClassModel) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(17439278522805508), classLoader, "DefaultNlsValuesRoot.ClassModel")) DefaultNlsValuesRoot.register(serializers) } @@ -72,6 +73,7 @@ class ClassModel private constructor( companion object : IMarshaller { override val _type: KClass = ClassModel::class + override val id: RdId get() = RdId(17439278522805508) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ClassModel { diff --git a/rd-kt/rd-gen/src/test/resources/testData/exampleModelTest/asis/ExampleModelNova.kt b/rd-kt/rd-gen/src/test/resources/testData/exampleModelTest/asis/ExampleModelNova.kt index 64a517c45..71a48cade 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/exampleModelTest/asis/ExampleModelNova.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/exampleModelTest/asis/ExampleModelNova.kt @@ -29,38 +29,39 @@ class ExampleModelNova private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(Selection) - serializers.register(Baz) - serializers.register(FooBar) - serializers.register(Class) - serializers.register(Struct) - serializers.register(OpenClass) - serializers.register(OpenStruct) - serializers.register(DerivedClass) - serializers.register(DerivedStruct) - serializers.register(DerivedOpenClass) - serializers.register(DerivedOpenStruct) - serializers.register(DerivedStructWith2Interfaces) - serializers.register(Document) - serializers.register(ScalarExample) - serializers.register(TextControl) - serializers.register(EnumSetTest.marshaller) - serializers.register(Z.marshaller) - serializers.register(Completion) - serializers.register(Foo_Unknown) - serializers.register(ScalarPrimer_Unknown) - serializers.register(A_Unknown) - serializers.register(BaseClass_Unknown) - serializers.register(BaseStruct_Unknown) - serializers.register(OpenClass_Unknown) - serializers.register(OpenStruct_Unknown) - serializers.register(DerivedOpenClass_Unknown) - serializers.register(DerivedOpenStruct_Unknown) - serializers.register(DerivedBaseClass_Unknown) - serializers.register(DerivedBaseStruct_Unknown) - serializers.register(BaseClassWithInterface_Unknown) - serializers.register(BaseStructWithInterface_Unknown) - serializers.register(DerivedClassWith2Interfaces_Unknown) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(576020388116153), classLoader, "org.example.Selection")) + serializers.register(LazyCompanionMarshaller(RdId(632584), classLoader, "org.example.Baz")) + serializers.register(LazyCompanionMarshaller(RdId(18972494688), classLoader, "org.example.FooBar")) + serializers.register(LazyCompanionMarshaller(RdId(609144101), classLoader, "org.example.Class")) + serializers.register(LazyCompanionMarshaller(RdId(19349429704), classLoader, "org.example.Struct")) + serializers.register(LazyCompanionMarshaller(RdId(572905478059643), classLoader, "org.example.OpenClass")) + serializers.register(LazyCompanionMarshaller(RdId(17760070285811506), classLoader, "org.example.OpenStruct")) + serializers.register(LazyCompanionMarshaller(RdId(-1667485286246826738), classLoader, "org.example.DerivedClass")) + serializers.register(LazyCompanionMarshaller(RdId(3648188347942988543), classLoader, "org.example.DerivedStruct")) + serializers.register(LazyCompanionMarshaller(RdId(-5037012260488689180), classLoader, "org.example.DerivedOpenClass")) + serializers.register(LazyCompanionMarshaller(RdId(-8573427485006989079), classLoader, "org.example.DerivedOpenStruct")) + serializers.register(LazyCompanionMarshaller(RdId(4287876202302424743), classLoader, "org.example.DerivedStructWith2Interfaces")) + serializers.register(LazyCompanionMarshaller(RdId(18177246065230), classLoader, "org.example.Document")) + serializers.register(LazyCompanionMarshaller(RdId(-3048302864262156661), classLoader, "org.example.ScalarExample")) + serializers.register(LazyCompanionMarshaller(RdId(554385840109775197), classLoader, "org.example.TextControl")) + serializers.register(LazyCompanionMarshaller(RdId(542326635061440960), classLoader, "org.example.EnumSetTest")) + serializers.register(LazyCompanionMarshaller(RdId(679), classLoader, "org.example.Z")) + serializers.register(LazyCompanionMarshaller(RdId(17442164506690639), classLoader, "org.example.Completion")) + serializers.register(LazyCompanionMarshaller(RdId(543167202472902558), classLoader, "org.example.Foo_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-427415512200834691), classLoader, "org.example.ScalarPrimer_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(560483126050681), classLoader, "org.example.A_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-8929432671501473473), classLoader, "org.example.BaseClass_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-8524399809491771292), classLoader, "org.example.BaseStruct_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-5669233277524003226), classLoader, "org.example.OpenClass_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(308061035262048285), classLoader, "org.example.OpenStruct_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-5977551086017277745), classLoader, "org.example.DerivedOpenClass_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(9196953045680089812), classLoader, "org.example.DerivedOpenStruct_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(9208993593714803624), classLoader, "org.example.DerivedBaseClass_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(364492200926270235), classLoader, "org.example.DerivedBaseStruct_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(1299733233306533130), classLoader, "org.example.BaseClassWithInterface_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-2819848318270682619), classLoader, "org.example.BaseStructWithInterface_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-485232411962447965), classLoader, "org.example.DerivedClassWith2Interfaces_Unknown")) } @@ -215,6 +216,7 @@ class A_Unknown ( companion object : IMarshaller { override val _type: KClass = A_Unknown::class + override val id: RdId get() = RdId(560483126050681) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): A_Unknown { @@ -351,6 +353,7 @@ class BaseClassWithInterface_Unknown ( companion object : IMarshaller { override val _type: KClass = BaseClassWithInterface_Unknown::class + override val id: RdId get() = RdId(1299733233306533130) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BaseClassWithInterface_Unknown { @@ -398,6 +401,7 @@ class BaseClass_Unknown ( companion object : IMarshaller { override val _type: KClass = BaseClass_Unknown::class + override val id: RdId get() = RdId(-8929432671501473473) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BaseClass_Unknown { @@ -510,6 +514,7 @@ class BaseStructWithInterface_Unknown ( companion object : IMarshaller { override val _type: KClass = BaseStructWithInterface_Unknown::class + override val id: RdId get() = RdId(-2819848318270682619) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BaseStructWithInterface_Unknown { @@ -565,6 +570,7 @@ class BaseStruct_Unknown ( companion object : IMarshaller { override val _type: KClass = BaseStruct_Unknown::class + override val id: RdId get() = RdId(-8524399809491771292) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BaseStruct_Unknown { @@ -649,6 +655,7 @@ class Baz private constructor( companion object : IMarshaller { override val _type: KClass = Baz::class + override val id: RdId get() = RdId(632584) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Baz { @@ -848,6 +855,7 @@ class Class ( companion object : IMarshaller { override val _type: KClass = Class::class + override val id: RdId get() = RdId(609144101) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Class { @@ -892,6 +900,7 @@ class Completion private constructor( companion object : IMarshaller { override val _type: KClass = Completion::class + override val id: RdId get() = RdId(17442164506690639) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Completion { @@ -996,6 +1005,7 @@ class DerivedBaseClass_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedBaseClass_Unknown::class + override val id: RdId get() = RdId(9208993593714803624) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedBaseClass_Unknown { @@ -1089,6 +1099,7 @@ class DerivedBaseStruct_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedBaseStruct_Unknown::class + override val id: RdId get() = RdId(364492200926270235) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedBaseStruct_Unknown { @@ -1156,6 +1167,7 @@ class DerivedClass ( companion object : IMarshaller { override val _type: KClass = DerivedClass::class + override val id: RdId get() = RdId(-1667485286246826738) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedClass { @@ -1250,6 +1262,7 @@ class DerivedClassWith2Interfaces_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedClassWith2Interfaces_Unknown::class + override val id: RdId get() = RdId(-485232411962447965) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedClassWith2Interfaces_Unknown { @@ -1307,6 +1320,7 @@ open class DerivedOpenClass ( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = DerivedOpenClass::class + override val id: RdId get() = RdId(-5037012260488689180) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedOpenClass { @@ -1374,6 +1388,7 @@ class DerivedOpenClass_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedOpenClass_Unknown::class + override val id: RdId get() = RdId(-5977551086017277745) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedOpenClass_Unknown { @@ -1431,6 +1446,7 @@ open class DerivedOpenStruct ( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = DerivedOpenStruct::class + override val id: RdId get() = RdId(-8573427485006989079) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedOpenStruct { @@ -1506,6 +1522,7 @@ class DerivedOpenStruct_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedOpenStruct_Unknown::class + override val id: RdId get() = RdId(9196953045680089812) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedOpenStruct_Unknown { @@ -1573,6 +1590,7 @@ class DerivedStruct ( companion object : IMarshaller { override val _type: KClass = DerivedStruct::class + override val id: RdId get() = RdId(3648188347942988543) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedStruct { @@ -1641,6 +1659,7 @@ class DerivedStructWith2Interfaces ( companion object : IMarshaller { override val _type: KClass = DerivedStructWith2Interfaces::class + override val id: RdId get() = RdId(4287876202302424743) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedStructWith2Interfaces { @@ -1711,6 +1730,7 @@ class Document private constructor( companion object : IMarshaller { override val _type: KClass = Document::class + override val id: RdId get() = RdId(18177246065230) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Document { @@ -1800,9 +1820,20 @@ enum class EnumSetTest { b, c; - companion object { + companion object : IMarshaller> { val marshaller = FrameworkMarshallers.enumSet() + + override val _type: KClass = EnumSetTest::class + override val id: RdId get() = RdId(542326635061440960) + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): EnumSet { + return marshaller.read(ctx, buffer) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: EnumSet) { + marshaller.write(ctx, buffer, value) + } } } @@ -1861,6 +1892,7 @@ class FooBar ( companion object : IMarshaller { override val _type: KClass = FooBar::class + override val id: RdId get() = RdId(18972494688) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): FooBar { @@ -1918,6 +1950,7 @@ class Foo_Unknown ( companion object : IMarshaller { override val _type: KClass = Foo_Unknown::class + override val id: RdId get() = RdId(543167202472902558) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Foo_Unknown { @@ -1997,6 +2030,7 @@ open class OpenClass ( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = OpenClass::class + override val id: RdId get() = RdId(572905478059643) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): OpenClass { @@ -2057,6 +2091,7 @@ class OpenClass_Unknown ( companion object : IMarshaller { override val _type: KClass = OpenClass_Unknown::class + override val id: RdId get() = RdId(-5669233277524003226) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): OpenClass_Unknown { @@ -2108,6 +2143,7 @@ open class OpenStruct ( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = OpenStruct::class + override val id: RdId get() = RdId(17760070285811506) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): OpenStruct { @@ -2175,6 +2211,7 @@ class OpenStruct_Unknown ( companion object : IMarshaller { override val _type: KClass = OpenStruct_Unknown::class + override val id: RdId get() = RdId(308061035262048285) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): OpenStruct_Unknown { @@ -2235,6 +2272,7 @@ data class ScalarExample ( companion object : IMarshaller { override val _type: KClass = ScalarExample::class + override val id: RdId get() = RdId(-3048302864262156661) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ScalarExample { @@ -2326,6 +2364,7 @@ class ScalarPrimer_Unknown ( companion object : IMarshaller { override val _type: KClass = ScalarPrimer_Unknown::class + override val id: RdId get() = RdId(-427415512200834691) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ScalarPrimer_Unknown { @@ -2390,6 +2429,7 @@ data class Selection ( companion object : IMarshaller { override val _type: KClass = Selection::class + override val id: RdId get() = RdId(576020388116153) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Selection { @@ -2467,6 +2507,7 @@ class Struct ( companion object : IMarshaller { override val _type: KClass = Struct::class + override val id: RdId get() = RdId(19349429704) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Struct { @@ -2521,6 +2562,7 @@ class TextControl private constructor( companion object : IMarshaller { override val _type: KClass = TextControl::class + override val id: RdId get() = RdId(554385840109775197) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): TextControl { @@ -2603,8 +2645,19 @@ enum class Z { Bar, z1; - companion object { + companion object : IMarshaller { val marshaller = FrameworkMarshallers.enum() + + override val _type: KClass = Z::class + override val id: RdId get() = RdId(679) + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Z { + return marshaller.read(ctx, buffer) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: Z) { + marshaller.write(ctx, buffer, value) + } } } diff --git a/rd-kt/rd-gen/src/test/resources/testData/exampleModelTest/reversed/ExampleModelNova.kt b/rd-kt/rd-gen/src/test/resources/testData/exampleModelTest/reversed/ExampleModelNova.kt index 818730302..73825db79 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/exampleModelTest/reversed/ExampleModelNova.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/exampleModelTest/reversed/ExampleModelNova.kt @@ -29,38 +29,39 @@ class ExampleModelNova private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(Selection) - serializers.register(Baz) - serializers.register(FooBar) - serializers.register(Class) - serializers.register(Struct) - serializers.register(OpenClass) - serializers.register(OpenStruct) - serializers.register(DerivedClass) - serializers.register(DerivedStruct) - serializers.register(DerivedOpenClass) - serializers.register(DerivedOpenStruct) - serializers.register(DerivedStructWith2Interfaces) - serializers.register(Document) - serializers.register(ScalarExample) - serializers.register(TextControl) - serializers.register(EnumSetTest.marshaller) - serializers.register(Z.marshaller) - serializers.register(Completion) - serializers.register(Foo_Unknown) - serializers.register(ScalarPrimer_Unknown) - serializers.register(A_Unknown) - serializers.register(BaseClass_Unknown) - serializers.register(BaseStruct_Unknown) - serializers.register(OpenClass_Unknown) - serializers.register(OpenStruct_Unknown) - serializers.register(DerivedOpenClass_Unknown) - serializers.register(DerivedOpenStruct_Unknown) - serializers.register(DerivedBaseClass_Unknown) - serializers.register(DerivedBaseStruct_Unknown) - serializers.register(BaseClassWithInterface_Unknown) - serializers.register(BaseStructWithInterface_Unknown) - serializers.register(DerivedClassWith2Interfaces_Unknown) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(576020388116153), classLoader, "org.example.Selection")) + serializers.register(LazyCompanionMarshaller(RdId(632584), classLoader, "org.example.Baz")) + serializers.register(LazyCompanionMarshaller(RdId(18972494688), classLoader, "org.example.FooBar")) + serializers.register(LazyCompanionMarshaller(RdId(609144101), classLoader, "org.example.Class")) + serializers.register(LazyCompanionMarshaller(RdId(19349429704), classLoader, "org.example.Struct")) + serializers.register(LazyCompanionMarshaller(RdId(572905478059643), classLoader, "org.example.OpenClass")) + serializers.register(LazyCompanionMarshaller(RdId(17760070285811506), classLoader, "org.example.OpenStruct")) + serializers.register(LazyCompanionMarshaller(RdId(-1667485286246826738), classLoader, "org.example.DerivedClass")) + serializers.register(LazyCompanionMarshaller(RdId(3648188347942988543), classLoader, "org.example.DerivedStruct")) + serializers.register(LazyCompanionMarshaller(RdId(-5037012260488689180), classLoader, "org.example.DerivedOpenClass")) + serializers.register(LazyCompanionMarshaller(RdId(-8573427485006989079), classLoader, "org.example.DerivedOpenStruct")) + serializers.register(LazyCompanionMarshaller(RdId(4287876202302424743), classLoader, "org.example.DerivedStructWith2Interfaces")) + serializers.register(LazyCompanionMarshaller(RdId(18177246065230), classLoader, "org.example.Document")) + serializers.register(LazyCompanionMarshaller(RdId(-3048302864262156661), classLoader, "org.example.ScalarExample")) + serializers.register(LazyCompanionMarshaller(RdId(554385840109775197), classLoader, "org.example.TextControl")) + serializers.register(LazyCompanionMarshaller(RdId(542326635061440960), classLoader, "org.example.EnumSetTest")) + serializers.register(LazyCompanionMarshaller(RdId(679), classLoader, "org.example.Z")) + serializers.register(LazyCompanionMarshaller(RdId(17442164506690639), classLoader, "org.example.Completion")) + serializers.register(LazyCompanionMarshaller(RdId(543167202472902558), classLoader, "org.example.Foo_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-427415512200834691), classLoader, "org.example.ScalarPrimer_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(560483126050681), classLoader, "org.example.A_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-8929432671501473473), classLoader, "org.example.BaseClass_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-8524399809491771292), classLoader, "org.example.BaseStruct_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-5669233277524003226), classLoader, "org.example.OpenClass_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(308061035262048285), classLoader, "org.example.OpenStruct_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-5977551086017277745), classLoader, "org.example.DerivedOpenClass_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(9196953045680089812), classLoader, "org.example.DerivedOpenStruct_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(9208993593714803624), classLoader, "org.example.DerivedBaseClass_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(364492200926270235), classLoader, "org.example.DerivedBaseStruct_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(1299733233306533130), classLoader, "org.example.BaseClassWithInterface_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-2819848318270682619), classLoader, "org.example.BaseStructWithInterface_Unknown")) + serializers.register(LazyCompanionMarshaller(RdId(-485232411962447965), classLoader, "org.example.DerivedClassWith2Interfaces_Unknown")) } @@ -215,6 +216,7 @@ class A_Unknown ( companion object : IMarshaller { override val _type: KClass = A_Unknown::class + override val id: RdId get() = RdId(560483126050681) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): A_Unknown { @@ -351,6 +353,7 @@ class BaseClassWithInterface_Unknown ( companion object : IMarshaller { override val _type: KClass = BaseClassWithInterface_Unknown::class + override val id: RdId get() = RdId(1299733233306533130) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BaseClassWithInterface_Unknown { @@ -398,6 +401,7 @@ class BaseClass_Unknown ( companion object : IMarshaller { override val _type: KClass = BaseClass_Unknown::class + override val id: RdId get() = RdId(-8929432671501473473) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BaseClass_Unknown { @@ -510,6 +514,7 @@ class BaseStructWithInterface_Unknown ( companion object : IMarshaller { override val _type: KClass = BaseStructWithInterface_Unknown::class + override val id: RdId get() = RdId(-2819848318270682619) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BaseStructWithInterface_Unknown { @@ -565,6 +570,7 @@ class BaseStruct_Unknown ( companion object : IMarshaller { override val _type: KClass = BaseStruct_Unknown::class + override val id: RdId get() = RdId(-8524399809491771292) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BaseStruct_Unknown { @@ -649,6 +655,7 @@ class Baz private constructor( companion object : IMarshaller { override val _type: KClass = Baz::class + override val id: RdId get() = RdId(632584) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Baz { @@ -848,6 +855,7 @@ class Class ( companion object : IMarshaller { override val _type: KClass = Class::class + override val id: RdId get() = RdId(609144101) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Class { @@ -892,6 +900,7 @@ class Completion private constructor( companion object : IMarshaller { override val _type: KClass = Completion::class + override val id: RdId get() = RdId(17442164506690639) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Completion { @@ -996,6 +1005,7 @@ class DerivedBaseClass_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedBaseClass_Unknown::class + override val id: RdId get() = RdId(9208993593714803624) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedBaseClass_Unknown { @@ -1089,6 +1099,7 @@ class DerivedBaseStruct_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedBaseStruct_Unknown::class + override val id: RdId get() = RdId(364492200926270235) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedBaseStruct_Unknown { @@ -1156,6 +1167,7 @@ class DerivedClass ( companion object : IMarshaller { override val _type: KClass = DerivedClass::class + override val id: RdId get() = RdId(-1667485286246826738) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedClass { @@ -1250,6 +1262,7 @@ class DerivedClassWith2Interfaces_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedClassWith2Interfaces_Unknown::class + override val id: RdId get() = RdId(-485232411962447965) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedClassWith2Interfaces_Unknown { @@ -1307,6 +1320,7 @@ open class DerivedOpenClass ( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = DerivedOpenClass::class + override val id: RdId get() = RdId(-5037012260488689180) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedOpenClass { @@ -1374,6 +1388,7 @@ class DerivedOpenClass_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedOpenClass_Unknown::class + override val id: RdId get() = RdId(-5977551086017277745) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedOpenClass_Unknown { @@ -1431,6 +1446,7 @@ open class DerivedOpenStruct ( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = DerivedOpenStruct::class + override val id: RdId get() = RdId(-8573427485006989079) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedOpenStruct { @@ -1506,6 +1522,7 @@ class DerivedOpenStruct_Unknown ( companion object : IMarshaller { override val _type: KClass = DerivedOpenStruct_Unknown::class + override val id: RdId get() = RdId(9196953045680089812) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedOpenStruct_Unknown { @@ -1573,6 +1590,7 @@ class DerivedStruct ( companion object : IMarshaller { override val _type: KClass = DerivedStruct::class + override val id: RdId get() = RdId(3648188347942988543) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedStruct { @@ -1641,6 +1659,7 @@ class DerivedStructWith2Interfaces ( companion object : IMarshaller { override val _type: KClass = DerivedStructWith2Interfaces::class + override val id: RdId get() = RdId(4287876202302424743) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): DerivedStructWith2Interfaces { @@ -1711,6 +1730,7 @@ class Document private constructor( companion object : IMarshaller { override val _type: KClass = Document::class + override val id: RdId get() = RdId(18177246065230) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Document { @@ -1800,9 +1820,20 @@ enum class EnumSetTest { b, c; - companion object { + companion object : IMarshaller> { val marshaller = FrameworkMarshallers.enumSet() + + override val _type: KClass = EnumSetTest::class + override val id: RdId get() = RdId(542326635061440960) + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): EnumSet { + return marshaller.read(ctx, buffer) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: EnumSet) { + marshaller.write(ctx, buffer, value) + } } } @@ -1861,6 +1892,7 @@ class FooBar ( companion object : IMarshaller { override val _type: KClass = FooBar::class + override val id: RdId get() = RdId(18972494688) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): FooBar { @@ -1918,6 +1950,7 @@ class Foo_Unknown ( companion object : IMarshaller { override val _type: KClass = Foo_Unknown::class + override val id: RdId get() = RdId(543167202472902558) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Foo_Unknown { @@ -1997,6 +2030,7 @@ open class OpenClass ( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = OpenClass::class + override val id: RdId get() = RdId(572905478059643) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): OpenClass { @@ -2057,6 +2091,7 @@ class OpenClass_Unknown ( companion object : IMarshaller { override val _type: KClass = OpenClass_Unknown::class + override val id: RdId get() = RdId(-5669233277524003226) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): OpenClass_Unknown { @@ -2108,6 +2143,7 @@ open class OpenStruct ( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = OpenStruct::class + override val id: RdId get() = RdId(17760070285811506) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): OpenStruct { @@ -2175,6 +2211,7 @@ class OpenStruct_Unknown ( companion object : IMarshaller { override val _type: KClass = OpenStruct_Unknown::class + override val id: RdId get() = RdId(308061035262048285) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): OpenStruct_Unknown { @@ -2235,6 +2272,7 @@ data class ScalarExample ( companion object : IMarshaller { override val _type: KClass = ScalarExample::class + override val id: RdId get() = RdId(-3048302864262156661) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ScalarExample { @@ -2326,6 +2364,7 @@ class ScalarPrimer_Unknown ( companion object : IMarshaller { override val _type: KClass = ScalarPrimer_Unknown::class + override val id: RdId get() = RdId(-427415512200834691) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ScalarPrimer_Unknown { @@ -2390,6 +2429,7 @@ data class Selection ( companion object : IMarshaller { override val _type: KClass = Selection::class + override val id: RdId get() = RdId(576020388116153) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Selection { @@ -2467,6 +2507,7 @@ class Struct ( companion object : IMarshaller { override val _type: KClass = Struct::class + override val id: RdId get() = RdId(19349429704) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Struct { @@ -2521,6 +2562,7 @@ class TextControl private constructor( companion object : IMarshaller { override val _type: KClass = TextControl::class + override val id: RdId get() = RdId(554385840109775197) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): TextControl { @@ -2603,8 +2645,19 @@ enum class Z { Bar, z1; - companion object { + companion object : IMarshaller { val marshaller = FrameworkMarshallers.enum() + + override val _type: KClass = Z::class + override val id: RdId get() = RdId(679) + + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Z { + return marshaller.read(ctx, buffer) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: Z) { + marshaller.write(ctx, buffer, value) + } } } diff --git a/rd-kt/rd-gen/src/test/resources/testData/extensionTest/asis/ExtensionRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/extensionTest/asis/ExtensionRoot.kt index 2e1f9b6e8..f933d5156 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/extensionTest/asis/ExtensionRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/extensionTest/asis/ExtensionRoot.kt @@ -25,8 +25,9 @@ class ExtensionRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(ClassWithStr) - serializers.register(StructWithStr) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(-1687597404575351130), classLoader, "ExtensionRoot.ClassWithStr")) + serializers.register(LazyCompanionMarshaller(RdId(-2602185343174852445), classLoader, "ExtensionRoot.StructWithStr")) ExtensionRoot.register(serializers) } @@ -75,6 +76,7 @@ class ClassWithStr ( companion object : IMarshaller { override val _type: KClass = ClassWithStr::class + override val id: RdId get() = RdId(-1687597404575351130) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ClassWithStr { @@ -141,6 +143,7 @@ data class StructWithStr ( companion object : IMarshaller { override val _type: KClass = StructWithStr::class + override val id: RdId get() = RdId(-2602185343174852445) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): StructWithStr { diff --git a/rd-kt/rd-gen/src/test/resources/testData/extensionTest/reversed/ExtensionRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/extensionTest/reversed/ExtensionRoot.kt index 2e1f9b6e8..f933d5156 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/extensionTest/reversed/ExtensionRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/extensionTest/reversed/ExtensionRoot.kt @@ -25,8 +25,9 @@ class ExtensionRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(ClassWithStr) - serializers.register(StructWithStr) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(-1687597404575351130), classLoader, "ExtensionRoot.ClassWithStr")) + serializers.register(LazyCompanionMarshaller(RdId(-2602185343174852445), classLoader, "ExtensionRoot.StructWithStr")) ExtensionRoot.register(serializers) } @@ -75,6 +76,7 @@ class ClassWithStr ( companion object : IMarshaller { override val _type: KClass = ClassWithStr::class + override val id: RdId get() = RdId(-1687597404575351130) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ClassWithStr { @@ -141,6 +143,7 @@ data class StructWithStr ( companion object : IMarshaller { override val _type: KClass = StructWithStr::class + override val id: RdId get() = RdId(-2602185343174852445) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): StructWithStr { diff --git a/rd-kt/rd-gen/src/test/resources/testData/interningModelsTest/asis/InternedModelsRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/interningModelsTest/asis/InternedModelsRoot.kt index f6001e2cc..c6d65de0f 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/interningModelsTest/asis/InternedModelsRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/interningModelsTest/asis/InternedModelsRoot.kt @@ -26,8 +26,9 @@ class InternedModelsRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(Editor) - serializers.register(Abc) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(18933576544), classLoader, "InternedModelsRoot.Editor")) + serializers.register(LazyCompanionMarshaller(RdId(631631), classLoader, "InternedModelsRoot.Abc")) InternedModelsRoot.register(serializers) } @@ -86,6 +87,7 @@ class Abc ( companion object : IMarshaller { override val _type: KClass = Abc::class + override val id: RdId get() = RdId(631631) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Abc { @@ -137,6 +139,7 @@ class Editor ( companion object : IMarshaller { override val _type: KClass = Editor::class + override val id: RdId get() = RdId(18933576544) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Editor { diff --git a/rd-kt/rd-gen/src/test/resources/testData/interningModelsTest/reversed/InternedModelsRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/interningModelsTest/reversed/InternedModelsRoot.kt index f6001e2cc..c6d65de0f 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/interningModelsTest/reversed/InternedModelsRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/interningModelsTest/reversed/InternedModelsRoot.kt @@ -26,8 +26,9 @@ class InternedModelsRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(Editor) - serializers.register(Abc) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(18933576544), classLoader, "InternedModelsRoot.Editor")) + serializers.register(LazyCompanionMarshaller(RdId(631631), classLoader, "InternedModelsRoot.Abc")) InternedModelsRoot.register(serializers) } @@ -86,6 +87,7 @@ class Abc ( companion object : IMarshaller { override val _type: KClass = Abc::class + override val id: RdId get() = RdId(631631) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Abc { @@ -137,6 +139,7 @@ class Editor ( companion object : IMarshaller { override val _type: KClass = Editor::class + override val id: RdId get() = RdId(18933576544) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): Editor { diff --git a/rd-kt/rd-gen/src/test/resources/testData/perClientId/asis/PerClientIdRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/perClientId/asis/PerClientIdRoot.kt index 76d488e7b..eda784399 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/perClientId/asis/PerClientIdRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/perClientId/asis/PerClientIdRoot.kt @@ -30,9 +30,10 @@ class PerClientIdRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(InnerClass) - serializers.register(PerClientIdStruct) - serializers.register(PerClientIdSignal) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(17599967238820149), classLoader, "com.jetbrains.rd.framework.test.cases.perClientId.InnerClass")) + serializers.register(LazyCompanionMarshaller(RdId(948719498381570149), classLoader, "com.jetbrains.rd.framework.test.cases.perClientId.PerClientIdStruct")) + serializers.register(LazyCompanionMarshaller(RdId(948719498371076920), classLoader, "com.jetbrains.rd.framework.test.cases.perClientId.PerClientIdSignal")) PerClientIdRoot.register(serializers) } @@ -123,6 +124,7 @@ class InnerClass private constructor( companion object : IMarshaller { override val _type: KClass = InnerClass::class + override val id: RdId get() = RdId(17599967238820149) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): InnerClass { @@ -200,6 +202,7 @@ class PerClientIdSignal ( companion object : IMarshaller { override val _type: KClass = PerClientIdSignal::class + override val id: RdId get() = RdId(948719498371076920) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): PerClientIdSignal { @@ -250,6 +253,7 @@ class PerClientIdStruct ( companion object : IMarshaller { override val _type: KClass = PerClientIdStruct::class + override val id: RdId get() = RdId(948719498381570149) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): PerClientIdStruct { diff --git a/rd-kt/rd-gen/src/test/resources/testData/perClientId/reversed/PerClientIdRoot.kt b/rd-kt/rd-gen/src/test/resources/testData/perClientId/reversed/PerClientIdRoot.kt index 76d488e7b..eda784399 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/perClientId/reversed/PerClientIdRoot.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/perClientId/reversed/PerClientIdRoot.kt @@ -30,9 +30,10 @@ class PerClientIdRoot private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(InnerClass) - serializers.register(PerClientIdStruct) - serializers.register(PerClientIdSignal) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(17599967238820149), classLoader, "com.jetbrains.rd.framework.test.cases.perClientId.InnerClass")) + serializers.register(LazyCompanionMarshaller(RdId(948719498381570149), classLoader, "com.jetbrains.rd.framework.test.cases.perClientId.PerClientIdStruct")) + serializers.register(LazyCompanionMarshaller(RdId(948719498371076920), classLoader, "com.jetbrains.rd.framework.test.cases.perClientId.PerClientIdSignal")) PerClientIdRoot.register(serializers) } @@ -123,6 +124,7 @@ class InnerClass private constructor( companion object : IMarshaller { override val _type: KClass = InnerClass::class + override val id: RdId get() = RdId(17599967238820149) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): InnerClass { @@ -200,6 +202,7 @@ class PerClientIdSignal ( companion object : IMarshaller { override val _type: KClass = PerClientIdSignal::class + override val id: RdId get() = RdId(948719498371076920) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): PerClientIdSignal { @@ -250,6 +253,7 @@ class PerClientIdStruct ( companion object : IMarshaller { override val _type: KClass = PerClientIdStruct::class + override val id: RdId get() = RdId(948719498381570149) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): PerClientIdStruct { diff --git a/rd-kt/rd-gen/src/test/resources/testData/recursivePolymorphicModelTest/asis/RecursivePolymorphicModel.kt b/rd-kt/rd-gen/src/test/resources/testData/recursivePolymorphicModelTest/asis/RecursivePolymorphicModel.kt index 67db67506..058ccdb01 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/recursivePolymorphicModelTest/asis/RecursivePolymorphicModel.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/recursivePolymorphicModelTest/asis/RecursivePolymorphicModel.kt @@ -27,8 +27,9 @@ class RecursivePolymorphicModel private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(BeTreeGridLine) - serializers.register(BeTreeGridLine_Unknown) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(8163186073645594862), classLoader, "org.example.BeTreeGridLine")) + serializers.register(LazyCompanionMarshaller(RdId(7212854712083994073), classLoader, "org.example.BeTreeGridLine_Unknown")) } @@ -109,6 +110,7 @@ open class BeTreeGridLine protected constructor( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = BeTreeGridLine::class + override val id: RdId get() = RdId(8163186073645594862) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BeTreeGridLine { @@ -179,6 +181,7 @@ class BeTreeGridLine_Unknown ( companion object : IMarshaller { override val _type: KClass = BeTreeGridLine_Unknown::class + override val id: RdId get() = RdId(7212854712083994073) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BeTreeGridLine_Unknown { diff --git a/rd-kt/rd-gen/src/test/resources/testData/recursivePolymorphicModelTest/reversed/RecursivePolymorphicModel.kt b/rd-kt/rd-gen/src/test/resources/testData/recursivePolymorphicModelTest/reversed/RecursivePolymorphicModel.kt index 67db67506..058ccdb01 100644 --- a/rd-kt/rd-gen/src/test/resources/testData/recursivePolymorphicModelTest/reversed/RecursivePolymorphicModel.kt +++ b/rd-kt/rd-gen/src/test/resources/testData/recursivePolymorphicModelTest/reversed/RecursivePolymorphicModel.kt @@ -27,8 +27,9 @@ class RecursivePolymorphicModel private constructor( companion object : ISerializersOwner { override fun registerSerializersCore(serializers: ISerializers) { - serializers.register(BeTreeGridLine) - serializers.register(BeTreeGridLine_Unknown) + val classLoader = javaClass.classLoader + serializers.register(LazyCompanionMarshaller(RdId(8163186073645594862), classLoader, "org.example.BeTreeGridLine")) + serializers.register(LazyCompanionMarshaller(RdId(7212854712083994073), classLoader, "org.example.BeTreeGridLine_Unknown")) } @@ -109,6 +110,7 @@ open class BeTreeGridLine protected constructor( companion object : IMarshaller, IAbstractDeclaration { override val _type: KClass = BeTreeGridLine::class + override val id: RdId get() = RdId(8163186073645594862) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BeTreeGridLine { @@ -179,6 +181,7 @@ class BeTreeGridLine_Unknown ( companion object : IMarshaller { override val _type: KClass = BeTreeGridLine_Unknown::class + override val id: RdId get() = RdId(7212854712083994073) @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): BeTreeGridLine_Unknown { diff --git a/rd-net/Test.RdFramework/Reflection/data/Generated/RefExt.cs b/rd-net/Test.RdFramework/Reflection/data/Generated/RefExt.cs index 1a4f9282b..592ef4811 100644 --- a/rd-net/Test.RdFramework/Reflection/data/Generated/RefExt.cs +++ b/rd-net/Test.RdFramework/Reflection/data/Generated/RefExt.cs @@ -1,6 +1,6 @@ //------------------------------------------------------------------------------ // -// This code was generated by a RdGen v1.12. +// This code was generated by a RdGen v1.13. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. diff --git a/rd-net/Test.RdFramework/Reflection/data/Generated/RefRoot.cs b/rd-net/Test.RdFramework/Reflection/data/Generated/RefRoot.cs index d7bb58ad8..d766bf0d7 100644 --- a/rd-net/Test.RdFramework/Reflection/data/Generated/RefRoot.cs +++ b/rd-net/Test.RdFramework/Reflection/data/Generated/RefRoot.cs @@ -1,6 +1,6 @@ //------------------------------------------------------------------------------ // -// This code was generated by a RdGen v1.12. +// This code was generated by a RdGen v1.13. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated.