diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/MessageEncoderPipelineImpl.kt b/mirai-core/src/commonMain/kotlin/message/protocol/MessageEncoderPipelineImpl.kt deleted file mode 100644 index bbf24555e..000000000 --- a/mirai-core/src/commonMain/kotlin/message/protocol/MessageEncoderPipelineImpl.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019-2022 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. - * - * https://github.com/mamoe/mirai/blob/dev/LICENSE - */ - -package net.mamoe.mirai.internal.message.protocol - -import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody -import net.mamoe.mirai.internal.pipeline.AbstractProcessorPipeline -import net.mamoe.mirai.internal.pipeline.PipelineConfiguration -import net.mamoe.mirai.message.data.SingleMessage -import net.mamoe.mirai.utils.* - - -internal open class MessageEncoderPipelineImpl : - AbstractProcessorPipeline, MessageEncoderContext, SingleMessage, ImMsgBody.Elem>( - PipelineConfiguration(stopWhenConsumed = true), - @OptIn(TestOnly::class) - defaultTraceLogging - ), - MessageEncoderPipeline { - - private inner class MessageEncoderContextImpl(attributes: TypeSafeMap) : MessageEncoderContext, - BaseContextImpl(attributes) { - override var generalFlags: ImMsgBody.Elem by lateinitMutableProperty { - ImMsgBody.Elem(generalFlags = ImMsgBody.GeneralFlags(pbReserve = PB_RESERVE_FOR_ELSE)) - } - } - - override fun createContext(attributes: TypeSafeMap): MessageEncoderContext = MessageEncoderContextImpl(attributes) - - companion object { - private val PB_RESERVE_FOR_ELSE = "78 00 F8 01 00 C8 02 00".hexToBytes() - - @TestOnly - val defaultTraceLogging: MiraiLoggerWithSwitch by lazy { - MiraiLogger.Factory.create(MessageEncoderPipelineImpl::class, "MessageEncoderPipeline") - .withSwitch(systemProp("mirai.message.encoder.pipeline.log.full", false)) - } - } -} \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/MessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/MessageProtocol.kt index d05022b38..c4c20e16f 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/MessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/MessageProtocol.kt @@ -9,6 +9,8 @@ package net.mamoe.mirai.internal.message.protocol +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder import net.mamoe.mirai.message.data.SingleMessage import kotlin.reflect.KClass diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/MessageProtocolFacade.kt b/mirai-core/src/commonMain/kotlin/message/protocol/MessageProtocolFacade.kt index b71235510..35fb5c496 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/MessageProtocolFacade.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/MessageProtocolFacade.kt @@ -15,6 +15,8 @@ import net.mamoe.mirai.internal.message.DeepMessageRefiner.refineDeep import net.mamoe.mirai.internal.message.EmptyRefineContext import net.mamoe.mirai.internal.message.LightMessageRefiner.refineLight import net.mamoe.mirai.internal.message.RefineContext +import net.mamoe.mirai.internal.message.protocol.decode.* +import net.mamoe.mirai.internal.message.protocol.encode.* import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.utils.runCoroutineInPlace import net.mamoe.mirai.message.data.* diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/MessageDecoderPipeline.kt b/mirai-core/src/commonMain/kotlin/message/protocol/decode/MessageDecoder.kt similarity index 56% rename from mirai-core/src/commonMain/kotlin/message/protocol/MessageDecoderPipeline.kt rename to mirai-core/src/commonMain/kotlin/message/protocol/decode/MessageDecoder.kt index 0f92730c7..513b32f8a 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/MessageDecoderPipeline.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/decode/MessageDecoder.kt @@ -7,30 +7,12 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -package net.mamoe.mirai.internal.message.protocol +package net.mamoe.mirai.internal.message.protocol.decode -import net.mamoe.mirai.Bot import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.pipeline.PipelineConsumptionMarker import net.mamoe.mirai.internal.pipeline.Processor -import net.mamoe.mirai.internal.pipeline.ProcessorPipeline -import net.mamoe.mirai.internal.pipeline.ProcessorPipelineContext -import net.mamoe.mirai.message.data.Message -import net.mamoe.mirai.message.data.MessageSourceKind -import net.mamoe.mirai.utils.TypeKey -import kotlin.coroutines.RestrictsSuspension -internal interface MessageDecoderPipeline : ProcessorPipeline - - -@RestrictsSuspension // Implementor can only call `MessageDecoderContext.process` and `processAlso` so there will be no suspension point -internal interface MessageDecoderContext : ProcessorPipelineContext { - companion object { - val BOT = TypeKey("bot") - val MESSAGE_SOURCE_KIND = TypeKey("messageSourceKind") - val GROUP_ID = TypeKey("groupId") // zero if not group - } -} internal interface MessageDecoder : PipelineConsumptionMarker { suspend fun MessageDecoderContext.process(data: ImMsgBody.Elem) diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/MessageDecoderPipelineImpl.kt b/mirai-core/src/commonMain/kotlin/message/protocol/decode/MessageDecoderPipeline.kt similarity index 63% rename from mirai-core/src/commonMain/kotlin/message/protocol/MessageDecoderPipelineImpl.kt rename to mirai-core/src/commonMain/kotlin/message/protocol/decode/MessageDecoderPipeline.kt index bc206dd38..68caa3b7c 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/MessageDecoderPipelineImpl.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/decode/MessageDecoderPipeline.kt @@ -7,14 +7,29 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -package net.mamoe.mirai.internal.message.protocol +package net.mamoe.mirai.internal.message.protocol.decode +import net.mamoe.mirai.Bot import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.pipeline.AbstractProcessorPipeline import net.mamoe.mirai.internal.pipeline.PipelineConfiguration +import net.mamoe.mirai.internal.pipeline.ProcessorPipeline +import net.mamoe.mirai.internal.pipeline.ProcessorPipelineContext import net.mamoe.mirai.message.data.Message +import net.mamoe.mirai.message.data.MessageSourceKind import net.mamoe.mirai.utils.* +import kotlin.coroutines.RestrictsSuspension +internal interface MessageDecoderPipeline : ProcessorPipeline + +@RestrictsSuspension // Implementor can only call `MessageDecoderContext.process` and `processAlso` so there will be no suspension point +internal interface MessageDecoderContext : ProcessorPipelineContext { + companion object { + val BOT = TypeKey("bot") + val MESSAGE_SOURCE_KIND = TypeKey("messageSourceKind") + val GROUP_ID = TypeKey("groupId") // zero if not group + } +} internal open class MessageDecoderPipelineImpl : AbstractProcessorPipeline( diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/encode/MessageEncoder.kt b/mirai-core/src/commonMain/kotlin/message/protocol/encode/MessageEncoder.kt new file mode 100644 index 000000000..3c9bf5eeb --- /dev/null +++ b/mirai-core/src/commonMain/kotlin/message/protocol/encode/MessageEncoder.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2019-2022 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +package net.mamoe.mirai.internal.message.protocol.encode + +import net.mamoe.mirai.internal.pipeline.PipelineConsumptionMarker +import net.mamoe.mirai.internal.pipeline.Processor +import net.mamoe.mirai.message.data.SingleMessage +import net.mamoe.mirai.utils.uncheckedCast +import kotlin.reflect.KClass + +internal fun interface MessageEncoder : PipelineConsumptionMarker { + suspend fun MessageEncoderContext.process(data: T) +} + + +/** + * Adapter for [MessageEncoder] to be used as [Processor]. + */ +internal class MessageEncoderProcessor( + private val encoder: MessageEncoder, + private val elementType: KClass, +) : Processor { + override suspend fun process(context: MessageEncoderContext, data: SingleMessage) { + if (elementType.isInstance(data)) { + @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") + encoder.run { context.process(data.uncheckedCast()) } + // TODO: 2022/4/27 handle exceptions + } + } +} \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/MessageEncoderPipeline.kt b/mirai-core/src/commonMain/kotlin/message/protocol/encode/MessageEncoderPipeline.kt similarity index 60% rename from mirai-core/src/commonMain/kotlin/message/protocol/MessageEncoderPipeline.kt rename to mirai-core/src/commonMain/kotlin/message/protocol/encode/MessageEncoderPipeline.kt index 5b975297f..f294ebc7b 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/MessageEncoderPipeline.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/encode/MessageEncoderPipeline.kt @@ -7,20 +7,18 @@ * https://github.com/mamoe/mirai/blob/dev/LICENSE */ -package net.mamoe.mirai.internal.message.protocol +package net.mamoe.mirai.internal.message.protocol.encode import net.mamoe.mirai.contact.ContactOrBot import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody -import net.mamoe.mirai.internal.pipeline.PipelineConsumptionMarker -import net.mamoe.mirai.internal.pipeline.Processor +import net.mamoe.mirai.internal.pipeline.AbstractProcessorPipeline +import net.mamoe.mirai.internal.pipeline.PipelineConfiguration import net.mamoe.mirai.internal.pipeline.ProcessorPipeline import net.mamoe.mirai.internal.pipeline.ProcessorPipelineContext import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.SingleMessage -import net.mamoe.mirai.utils.TypeKey -import net.mamoe.mirai.utils.uncheckedCast +import net.mamoe.mirai.utils.* import kotlin.coroutines.RestrictsSuspension -import kotlin.reflect.KClass internal interface MessageEncoderPipeline : ProcessorPipeline, SingleMessage, ImMsgBody.Elem> { @@ -60,23 +58,30 @@ internal interface MessageEncoderContext : ProcessorPipelineContext, MessageEncoderContext, SingleMessage, ImMsgBody.Elem>( + PipelineConfiguration(stopWhenConsumed = true), + @OptIn(TestOnly::class) + defaultTraceLogging + ), + MessageEncoderPipeline { -internal fun interface MessageEncoder : PipelineConsumptionMarker { - suspend fun MessageEncoderContext.process(data: T) -} - -/** - * Adapter for [MessageEncoder] to be used as [Processor]. - */ -internal class MessageEncoderProcessor( - private val encoder: MessageEncoder, - private val elementType: KClass, -) : Processor { - override suspend fun process(context: MessageEncoderContext, data: SingleMessage) { - if (elementType.isInstance(data)) { - @Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") - encoder.run { context.process(data.uncheckedCast()) } - // TODO: 2022/4/27 handle exceptions + private inner class MessageEncoderContextImpl(attributes: TypeSafeMap) : MessageEncoderContext, + BaseContextImpl(attributes) { + override var generalFlags: ImMsgBody.Elem by lateinitMutableProperty { + ImMsgBody.Elem(generalFlags = ImMsgBody.GeneralFlags(pbReserve = PB_RESERVE_FOR_ELSE)) } } -} + + override fun createContext(attributes: TypeSafeMap): MessageEncoderContext = MessageEncoderContextImpl(attributes) + + companion object { + private val PB_RESERVE_FOR_ELSE = "78 00 F8 01 00 C8 02 00".hexToBytes() + + @TestOnly + val defaultTraceLogging: MiraiLoggerWithSwitch by lazy { + MiraiLogger.Factory.create(MessageEncoderPipelineImpl::class, "MessageEncoderPipeline") + .withSwitch(systemProp("mirai.message.encoder.pipeline.log.full", false)) + } + } +} \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/CustomMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/CustomMessageProtocol.kt index 264be5a6f..cca4fcd31 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/CustomMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/CustomMessageProtocol.kt @@ -9,7 +9,12 @@ package net.mamoe.mirai.internal.message.protocol.impl -import net.mamoe.mirai.internal.message.protocol.* +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.message.data.CustomMessage import net.mamoe.mirai.utils.read diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FaceProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FaceProtocol.kt index 8d7f4f4d6..d3eccac07 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FaceProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FaceProtocol.kt @@ -10,7 +10,12 @@ package net.mamoe.mirai.internal.message.protocol.impl import kotlinx.io.core.toByteArray -import net.mamoe.mirai.internal.message.protocol.* +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext import net.mamoe.mirai.internal.network.protocol.data.proto.HummerCommelem import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.utils.io.serialization.loadAs diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt index 2b238a618..01e23fba1 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt @@ -11,10 +11,10 @@ package net.mamoe.mirai.internal.message.protocol.impl import kotlinx.io.core.readUShort import net.mamoe.mirai.internal.message.data.FileMessageImpl -import net.mamoe.mirai.internal.message.protocol.MessageDecoder -import net.mamoe.mirai.internal.message.protocol.MessageDecoderContext import net.mamoe.mirai.internal.message.protocol.MessageProtocol import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.network.protocol.data.proto.ObjMsg import net.mamoe.mirai.internal.utils.io.serialization.readProtoBuf diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FlashImageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FlashImageProtocol.kt index d1cb2381c..eb62154eb 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FlashImageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FlashImageProtocol.kt @@ -14,9 +14,14 @@ import net.mamoe.mirai.contact.User import net.mamoe.mirai.internal.message.image.OnlineFriendImageImpl import net.mamoe.mirai.internal.message.image.OnlineGroupImageImpl import net.mamoe.mirai.internal.message.image.friendImageId -import net.mamoe.mirai.internal.message.protocol.* -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.collectGeneralFlags -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.contact +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.collectGeneralFlags +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.contact import net.mamoe.mirai.internal.network.protocol.data.proto.HummerCommelem import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.utils.io.serialization.loadAs diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/IgnoredMessagesProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/IgnoredMessagesProtocol.kt index 9c33de01c..1e21c7b6e 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/IgnoredMessagesProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/IgnoredMessagesProtocol.kt @@ -10,7 +10,12 @@ package net.mamoe.mirai.internal.message.protocol.impl import net.mamoe.mirai.internal.message.flags.InternalFlagOnlyMessage -import net.mamoe.mirai.internal.message.protocol.* +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.message.data.ForwardMessage import net.mamoe.mirai.message.data.MessageSource diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/ImageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/ImageProtocol.kt index d70cf9494..2e07ff2e8 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/ImageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/ImageProtocol.kt @@ -11,8 +11,13 @@ package net.mamoe.mirai.internal.message.protocol.impl import net.mamoe.mirai.contact.User import net.mamoe.mirai.internal.message.image.* -import net.mamoe.mirai.internal.message.protocol.* -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.contact +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.contact import net.mamoe.mirai.internal.network.protocol.data.proto.CustomFace import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.utils.io.serialization.loadAs diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/MarketFaceProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/MarketFaceProtocol.kt index a41cc042c..52cb429cc 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/MarketFaceProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/MarketFaceProtocol.kt @@ -10,8 +10,13 @@ package net.mamoe.mirai.internal.message.protocol.impl import net.mamoe.mirai.internal.message.data.MarketFaceImpl -import net.mamoe.mirai.internal.message.protocol.* -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.collectGeneralFlags +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.collectGeneralFlags import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.message.data.Dice import net.mamoe.mirai.message.data.PlainText diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/MusicShareProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/MusicShareProtocol.kt index d1d646201..418f1286e 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/MusicShareProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/MusicShareProtocol.kt @@ -9,10 +9,10 @@ package net.mamoe.mirai.internal.message.protocol.impl -import net.mamoe.mirai.internal.message.protocol.MessageEncoder -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext import net.mamoe.mirai.internal.message.protocol.MessageProtocol import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext import net.mamoe.mirai.message.data.MusicShare import net.mamoe.mirai.message.data.PlainText import net.mamoe.mirai.message.data.content diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/PokeMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/PokeMessageProtocol.kt index 040a08991..70720c38c 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/PokeMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/PokeMessageProtocol.kt @@ -9,7 +9,12 @@ package net.mamoe.mirai.internal.message.protocol.impl -import net.mamoe.mirai.internal.message.protocol.* +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext import net.mamoe.mirai.internal.network.protocol.data.proto.HummerCommelem import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.utils.io.serialization.loadAs diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/PttMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/PttMessageProtocol.kt index 867b88d45..a25f1b443 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/PttMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/PttMessageProtocol.kt @@ -9,11 +9,11 @@ package net.mamoe.mirai.internal.message.protocol.impl -import net.mamoe.mirai.internal.message.protocol.MessageEncoder -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.collectGeneralFlags import net.mamoe.mirai.internal.message.protocol.MessageProtocol import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.collectGeneralFlags import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.message.data.PttMessage import net.mamoe.mirai.utils.hexToBytes diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt index 6396cebb9..778fe5a16 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt @@ -11,11 +11,16 @@ package net.mamoe.mirai.internal.message.protocol.impl import net.mamoe.mirai.contact.AnonymousMember import net.mamoe.mirai.contact.Group -import net.mamoe.mirai.internal.message.protocol.* -import net.mamoe.mirai.internal.message.protocol.MessageDecoderContext.Companion.BOT -import net.mamoe.mirai.internal.message.protocol.MessageDecoderContext.Companion.GROUP_ID -import net.mamoe.mirai.internal.message.protocol.MessageDecoderContext.Companion.MESSAGE_SOURCE_KIND -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.contact +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext.Companion.BOT +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext.Companion.GROUP_ID +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext.Companion.MESSAGE_SOURCE_KIND +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.contact import net.mamoe.mirai.internal.message.source.MessageSourceInternal import net.mamoe.mirai.internal.message.source.OfflineMessageSourceImplData import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/RichMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/RichMessageProtocol.kt index 1a2bba391..3d2b1b3b5 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/RichMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/RichMessageProtocol.kt @@ -13,8 +13,13 @@ import kotlinx.io.core.toByteArray import net.mamoe.mirai.internal.message.data.ForwardMessageInternal import net.mamoe.mirai.internal.message.data.LightAppInternal import net.mamoe.mirai.internal.message.data.LongMessageInternal -import net.mamoe.mirai.internal.message.protocol.* -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.collectGeneralFlags +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.collectGeneralFlags import net.mamoe.mirai.internal.message.runWithBugReport import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.message.data.* diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/TextProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/TextProtocol.kt index 3e0cff8fd..e96ba825d 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/TextProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/TextProtocol.kt @@ -15,10 +15,15 @@ import kotlinx.io.core.readBytes import kotlinx.io.core.readUInt import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.nameCardOrNick -import net.mamoe.mirai.internal.message.protocol.* -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.CONTACT -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.isForward -import net.mamoe.mirai.internal.message.protocol.MessageEncoderContext.Companion.originalMessage +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.CONTACT +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.isForward +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.originalMessage import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.message.data.* import net.mamoe.mirai.utils.read diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/UnsupportedMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/UnsupportedMessageProtocol.kt index 31769e044..13f0aae10 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/UnsupportedMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/UnsupportedMessageProtocol.kt @@ -10,7 +10,12 @@ package net.mamoe.mirai.internal.message.protocol.impl import net.mamoe.mirai.internal.message.data.UnsupportedMessageImpl -import net.mamoe.mirai.internal.message.protocol.* +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody internal class UnsupportedMessageProtocol : MessageProtocol(priority = PRIORITY_UNSUPPORTED) { diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/VipFaceProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/VipFaceProtocol.kt index e86a79d45..57fe9cc71 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/VipFaceProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/VipFaceProtocol.kt @@ -9,7 +9,12 @@ package net.mamoe.mirai.internal.message.protocol.impl -import net.mamoe.mirai.internal.message.protocol.* +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.ProcessorCollector +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext import net.mamoe.mirai.internal.network.protocol.data.proto.HummerCommelem import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.utils.io.serialization.loadAs diff --git a/mirai-core/src/commonTest/kotlin/message/protocol/impl/AbstractMessageProtocolTest.kt b/mirai-core/src/commonTest/kotlin/message/protocol/impl/AbstractMessageProtocolTest.kt index 6db200857..71182262c 100644 --- a/mirai-core/src/commonTest/kotlin/message/protocol/impl/AbstractMessageProtocolTest.kt +++ b/mirai-core/src/commonTest/kotlin/message/protocol/impl/AbstractMessageProtocolTest.kt @@ -15,7 +15,12 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import net.mamoe.mirai.contact.ContactOrBot import net.mamoe.mirai.contact.Group import net.mamoe.mirai.internal.contact.inferMessageSourceKind -import net.mamoe.mirai.internal.message.protocol.* +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.internal.message.protocol.MessageProtocolFacade +import net.mamoe.mirai.internal.message.protocol.MessageProtocolFacadeImpl +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderPipelineImpl +import net.mamoe.mirai.internal.message.protocol.decodeAndRefineLight +import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderPipelineImpl import net.mamoe.mirai.internal.network.framework.AbstractMockNetworkHandlerTest import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.notice.processors.GroupExtensions diff --git a/mirai-core/src/commonTest/kotlin/testFramework/message/protocol/MessageDecodingRecorder.kt b/mirai-core/src/commonTest/kotlin/testFramework/message/protocol/MessageDecodingRecorder.kt index f620950de..d5ab49be5 100644 --- a/mirai-core/src/commonTest/kotlin/testFramework/message/protocol/MessageDecodingRecorder.kt +++ b/mirai-core/src/commonTest/kotlin/testFramework/message/protocol/MessageDecodingRecorder.kt @@ -9,8 +9,8 @@ package net.mamoe.mirai.internal.testFramework.message.protocol -import net.mamoe.mirai.internal.message.protocol.MessageDecoder -import net.mamoe.mirai.internal.message.protocol.MessageDecoderContext +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.internal.testFramework.codegen.ValueDescAnalyzer import net.mamoe.mirai.internal.testFramework.desensitizer.Desensitizer.Companion.generateAndDesensitize diff --git a/mirai-core/src/jvmTest/kotlin/bootstrap/RunMessageDecodingRecorder.kt b/mirai-core/src/jvmTest/kotlin/bootstrap/RunMessageDecodingRecorder.kt index 6be0c6e54..e91294c32 100644 --- a/mirai-core/src/jvmTest/kotlin/bootstrap/RunMessageDecodingRecorder.kt +++ b/mirai-core/src/jvmTest/kotlin/bootstrap/RunMessageDecodingRecorder.kt @@ -12,8 +12,8 @@ package net.mamoe.mirai.internal.bootstrap import net.mamoe.mirai.Bot import net.mamoe.mirai.BotFactory import net.mamoe.mirai.internal.asQQAndroidBot -import net.mamoe.mirai.internal.message.protocol.MessageDecoderProcessor import net.mamoe.mirai.internal.message.protocol.MessageProtocolFacade +import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderProcessor import net.mamoe.mirai.internal.testFramework.desensitizer.Desensitizer import net.mamoe.mirai.internal.testFramework.message.protocol.MessageDecodingRecorder import net.mamoe.mirai.utils.BotConfiguration