Fix debug message leak; fix #1955

This commit is contained in:
Karlatemp 2022-03-30 14:38:53 +08:00
parent 304220708a
commit 629226553c
No known key found for this signature in database
GPG Key ID: C6B606FF23D8FED7
2 changed files with 12 additions and 9 deletions

View File

@ -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<TarsTag>() {
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 {

View File

@ -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(