mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-28 09:30:23 +08:00
Move SerialDescriptor.copy to mirai-core-utils
This commit is contained in:
parent
8d25025d24
commit
0f41c225f9
@ -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<MessageSource> by SerialData.serializer().map(
|
||||
|
@ -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.*
|
||||
|
||||
/**
|
||||
* 文件消息.
|
||||
|
@ -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 <T> File.loadNotBlankAs(
|
||||
@ -26,3 +29,20 @@ public fun <T> 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),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user