mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-01 08:20:37 +08:00
Hide Message serializers and postpone implementations later
This commit is contained in:
parent
ffa23ec5ef
commit
fc72811e2a
@ -166,6 +166,7 @@ private val builtInSerializersModule by lazy {
|
||||
subclass(FlashImage::class, FlashImage.serializer())
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
contextual(Message::class, Message.Serializer)
|
||||
// contextual(SingleMessage::class, SingleMessage.Serializer)
|
||||
contextual(MessageChain::class, MessageChain.Serializer)
|
||||
|
@ -73,6 +73,7 @@ import kotlin.internal.LowPriorityInOverloadResolution
|
||||
*
|
||||
* @see Contact.sendMessage 发送消息
|
||||
*/
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
@Serializable(Message.Serializer::class)
|
||||
public interface Message { // must be interface. Don't consider any changes.
|
||||
|
||||
@ -197,15 +198,18 @@ public interface Message { // must be interface. Don't consider any changes.
|
||||
public operator fun plus(another: Sequence<Message>): MessageChain =
|
||||
another.fold(this, Message::plus).asMessageChain()
|
||||
|
||||
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
|
||||
public object Serializer :
|
||||
MessageSerializer by MessageSerializerImpl,
|
||||
KSerializer<Message> by PolymorphicSerializer(Message::class)
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public companion object {
|
||||
/**
|
||||
* 从 JSON 字符串解析 [Message]
|
||||
* @see serializeToJsonString
|
||||
*/
|
||||
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
public fun deserializeFromJsonString(
|
||||
@ -219,6 +223,7 @@ public interface Message { // must be interface. Don't consider any changes.
|
||||
* 将 [Message] 序列化为 JSON 字符串.
|
||||
* @see deserializeFromJsonString
|
||||
*/
|
||||
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
public fun Message.serializeToJsonString(
|
||||
@ -231,6 +236,7 @@ public interface Message { // must be interface. Don't consider any changes.
|
||||
* @see serializeToJsonString
|
||||
* @see StringFormat.encodeToString
|
||||
*/
|
||||
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
|
||||
@ExperimentalSerializationApi
|
||||
@JvmStatic
|
||||
public fun Message.serializeToString(format: StringFormat): String =
|
||||
|
@ -93,7 +93,8 @@ public interface MessageChain : Message, List<SingleMessage>, RandomAccess, Coda
|
||||
asSequence().any { key.safeCast.invoke(it) != null }
|
||||
|
||||
public object Serializer : KSerializer<MessageChain> {
|
||||
private val delegate = ListSerializer(Message.Serializer)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
private val delegate = ListSerializer<Message>(Message.Serializer)
|
||||
override val descriptor: SerialDescriptor = delegate.descriptor
|
||||
override fun deserialize(decoder: Decoder): MessageChain = delegate.deserialize(decoder).asMessageChain()
|
||||
override fun serialize(encoder: Encoder, value: MessageChain): Unit = delegate.serialize(encoder, value)
|
||||
@ -103,11 +104,13 @@ public interface MessageChain : Message, List<SingleMessage>, RandomAccess, Coda
|
||||
forEach { it.safeCast<CodableMessage>()?.appendMiraiCode(builder) }
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
public companion object {
|
||||
/**
|
||||
* 从 JSON 字符串解析 [MessageChain]
|
||||
* @see serializeToJsonString
|
||||
*/
|
||||
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
public fun deserializeFromJsonString(
|
||||
@ -121,6 +124,7 @@ public interface MessageChain : Message, List<SingleMessage>, RandomAccess, Coda
|
||||
* 将 [MessageChain] 序列化为 JSON 字符串.
|
||||
* @see deserializeFromJsonString
|
||||
*/
|
||||
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
public fun MessageChain.serializeToJsonString(
|
||||
@ -133,6 +137,7 @@ public interface MessageChain : Message, List<SingleMessage>, RandomAccess, Coda
|
||||
* @see serializeToJsonString
|
||||
* @see StringFormat.encodeToString
|
||||
*/
|
||||
@Deprecated("消息序列化仍未稳定,请在 2.0-RC 再使用", level = DeprecationLevel.HIDDEN)
|
||||
@ExperimentalSerializationApi
|
||||
@JvmStatic
|
||||
public fun MessageChain.serializeToString(format: StringFormat): String =
|
||||
|
@ -46,7 +46,7 @@ import kotlin.random.Random
|
||||
// not object for ServiceLoader.
|
||||
internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
||||
companion object INSTANCE : MiraiImpl() {
|
||||
@Suppress("ObjectPropertyName", "unused")
|
||||
@Suppress("ObjectPropertyName", "unused", "DEPRECATION_ERROR")
|
||||
private val _init = Mirai.let {
|
||||
CIO // init
|
||||
Message.Serializer.registerSerializer(OfflineGroupImage::class, OfflineGroupImage.serializer())
|
||||
|
@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
internal class MessageSerializationTest {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
private val module get() = Message.Serializer.serializersModule
|
||||
private val format
|
||||
get() = Json {
|
||||
|
Loading…
Reference in New Issue
Block a user