diff --git a/mirai-core-api/src/commonMain/kotlin/internal/message/MessageSerializersImpl.kt b/mirai-core-api/src/commonMain/kotlin/internal/message/MessageSerializersImpl.kt index bf201e955..e7a99ed28 100644 --- a/mirai-core-api/src/commonMain/kotlin/internal/message/MessageSerializersImpl.kt +++ b/mirai-core-api/src/commonMain/kotlin/internal/message/MessageSerializersImpl.kt @@ -23,27 +23,11 @@ import net.mamoe.mirai.Mirai import net.mamoe.mirai.message.MessageSerializers import net.mamoe.mirai.message.data.* import net.mamoe.mirai.utils.MiraiInternalApi +import net.mamoe.mirai.utils.takeElementsFrom import kotlin.reflect.KClass import kotlin.reflect.full.allSuperclasses import kotlin.reflect.full.isSubclassOf -internal fun SerialDescriptor.copy(newName: String): SerialDescriptor = - buildClassSerialDescriptor(newName) { takeElementsFrom(this@copy) } - - -internal fun ClassSerialDescriptorBuilder.takeElementsFrom(descriptor: SerialDescriptor) { - with(descriptor) { - repeat(descriptor.elementsCount) { index -> - element( - elementName = getElementName(index), - descriptor = getElementDescriptor(index), - annotations = getElementAnnotations(index), - isOptional = isElementOptional(index), - ) - } - } -} - @MiraiInternalApi public open class MessageSourceSerializerImpl(serialName: String) : KSerializer by SerialData.serializer().map( diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/FileMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/FileMessage.kt index 06fae3e1a..69b0064a6 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/FileMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/FileMessage.kt @@ -20,14 +20,10 @@ import net.mamoe.kjbb.JvmBlockingBridge import net.mamoe.mirai.Mirai import net.mamoe.mirai.contact.FileSupported import net.mamoe.mirai.event.events.MessageEvent -import net.mamoe.mirai.internal.message.copy import net.mamoe.mirai.internal.message.map import net.mamoe.mirai.message.code.CodableMessage import net.mamoe.mirai.message.code.internal.appendStringAsMiraiCode -import net.mamoe.mirai.utils.MiraiExperimentalApi -import net.mamoe.mirai.utils.MiraiInternalApi -import net.mamoe.mirai.utils.RemoteFile -import net.mamoe.mirai.utils.safeCast +import net.mamoe.mirai.utils.* /** * 文件消息. diff --git a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt index 7b6e57b4b..85e5e9724 100644 --- a/mirai-core-utils/src/commonMain/kotlin/Serialization.kt +++ b/mirai-core-utils/src/commonMain/kotlin/Serialization.kt @@ -15,6 +15,9 @@ package net.mamoe.mirai.utils import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.StringFormat +import kotlinx.serialization.descriptors.ClassSerialDescriptorBuilder +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.descriptors.buildClassSerialDescriptor import java.io.File public fun File.loadNotBlankAs( @@ -26,3 +29,20 @@ public fun File.loadNotBlankAs( } return stringFormat.decodeFromString(serializer, this.readText()) } + + +public fun SerialDescriptor.copy(newName: String): SerialDescriptor = + buildClassSerialDescriptor(newName) { takeElementsFrom(this@copy) } + +public fun ClassSerialDescriptorBuilder.takeElementsFrom(descriptor: SerialDescriptor) { + with(descriptor) { + repeat(descriptor.elementsCount) { index -> + element( + elementName = getElementName(index), + descriptor = getElementDescriptor(index), + annotations = getElementAnnotations(index), + isOptional = isElementOptional(index), + ) + } + } +}