From 629226553c2725c535ed4b53f9815a31b83d398d Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Wed, 30 Mar 2022 14:38:53 +0800 Subject: [PATCH] Fix debug message leak; fix #1955 --- .../serialization/tars/internal/TarsDecoder.kt | 5 ++++- .../io/serialization/tars/internal/TarsInput.kt | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsDecoder.kt b/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsDecoder.kt index 0f36403e1..457059cbd 100644 --- a/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsDecoder.kt +++ b/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsDecoder.kt @@ -43,7 +43,9 @@ internal class DebugLogger( @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class) internal class TarsDecoder( - val input: TarsInput, override val serializersModule: SerializersModule, val debugLogger: DebugLogger + val input: TarsInput, + override val serializersModule: SerializersModule, + val debugLogger: DebugLogger, ) : TaggedDecoder() { override fun SerialDescriptor.getTag(index: Int): TarsTag { val annotations = this.getElementAnnotations(index) @@ -228,6 +230,7 @@ internal class TarsDecoder( companion object { val logger = MiraiLogger.Factory.create(TarsDecoder::class, "TarsDecoder") + } override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder { diff --git a/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsInput.kt b/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsInput.kt index a8078894f..42195b6f7 100644 --- a/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsInput.kt +++ b/mirai-core/src/commonMain/kotlin/utils/io/serialization/tars/internal/TarsInput.kt @@ -39,7 +39,7 @@ internal class TarsInput( fun peekNextHead(): TarsHead? { _nextHead?.let { return it } return readNextHeadButDoNotAssignTo_Head(true).also { _nextHead = it; }.also { - println("Peek next head: $it") + debugLogger.println("Peek next head: $it") } } @@ -123,7 +123,7 @@ internal class TarsInput( if (tag <= hd.tag || hd.type == 11.toByte()) { return tag == hd.tag } - println("Discard $tag, $hd, ${hd.size}") + debugLogger.println("Discard $tag, $hd, ${hd.size}") input.discardExact(hd.size) skipField(hd.type) } @@ -152,7 +152,7 @@ internal class TarsInput( @OptIn(ExperimentalUnsignedTypes::class) @PublishedApi internal fun skipField(type: Byte) { - println { + debugLogger.println { "skipping ${ TarsHead.findTarsTypeName( type @@ -171,7 +171,7 @@ internal class TarsInput( Tars.MAP -> { // map debugLogger.structureHierarchy++ repeat(readInt32(0).also { - println("SIZE = $it") + debugLogger.println("SIZE = $it") } * 2) { skipField(nextHead().type) } @@ -180,7 +180,7 @@ internal class TarsInput( Tars.LIST -> { // list debugLogger.structureHierarchy++ repeat(readInt32(0).also { - println("SIZE = $it") + debugLogger.println("SIZE = $it") }) { skipField(nextHead().type) } @@ -218,7 +218,7 @@ internal class TarsInput( // region readers fun readTarsIntValue(head: TarsHead): Int { - //println("readTarsIntValue: $head") + //debugLogger.println("readTarsIntValue: $head") return readTarsIntValue(head.type, head) } @@ -254,7 +254,7 @@ internal class TarsInput( } fun readTarsByteValue(head: TarsHead): Byte { - //println("readTarsByteValue: $head") + //debugLogger.println("readTarsByteValue: $head") return when (head.type) { Tars.ZERO_TYPE -> 0 Tars.BYTE -> input.readByte() @@ -272,7 +272,7 @@ internal class TarsInput( @OptIn(ExperimentalUnsignedTypes::class) fun readTarsStringValue(head: TarsHead): String { - //println("readTarsStringValue: $head") + //debugLogger.println("readTarsStringValue: $head") return when (head.type) { Tars.STRING1 -> input.readString(input.readUByte().toInt(), charset = charset) Tars.STRING4 -> input.readString(