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) @OptIn(InternalSerializationApi::class, ExperimentalSerializationApi::class)
internal class TarsDecoder( 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>() { ) : TaggedDecoder<TarsTag>() {
override fun SerialDescriptor.getTag(index: Int): TarsTag { override fun SerialDescriptor.getTag(index: Int): TarsTag {
val annotations = this.getElementAnnotations(index) val annotations = this.getElementAnnotations(index)
@ -228,6 +230,7 @@ internal class TarsDecoder(
companion object { companion object {
val logger = MiraiLogger.Factory.create(TarsDecoder::class, "TarsDecoder") val logger = MiraiLogger.Factory.create(TarsDecoder::class, "TarsDecoder")
} }
override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder { override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder {

View File

@ -39,7 +39,7 @@ internal class TarsInput(
fun peekNextHead(): TarsHead? { fun peekNextHead(): TarsHead? {
_nextHead?.let { return it } _nextHead?.let { return it }
return readNextHeadButDoNotAssignTo_Head(true).also { _nextHead = it; }.also { 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()) { if (tag <= hd.tag || hd.type == 11.toByte()) {
return tag == hd.tag return tag == hd.tag
} }
println("Discard $tag, $hd, ${hd.size}") debugLogger.println("Discard $tag, $hd, ${hd.size}")
input.discardExact(hd.size) input.discardExact(hd.size)
skipField(hd.type) skipField(hd.type)
} }
@ -152,7 +152,7 @@ internal class TarsInput(
@OptIn(ExperimentalUnsignedTypes::class) @OptIn(ExperimentalUnsignedTypes::class)
@PublishedApi @PublishedApi
internal fun skipField(type: Byte) { internal fun skipField(type: Byte) {
println { debugLogger.println {
"skipping ${ "skipping ${
TarsHead.findTarsTypeName( TarsHead.findTarsTypeName(
type type
@ -171,7 +171,7 @@ internal class TarsInput(
Tars.MAP -> { // map Tars.MAP -> { // map
debugLogger.structureHierarchy++ debugLogger.structureHierarchy++
repeat(readInt32(0).also { repeat(readInt32(0).also {
println("SIZE = $it") debugLogger.println("SIZE = $it")
} * 2) { } * 2) {
skipField(nextHead().type) skipField(nextHead().type)
} }
@ -180,7 +180,7 @@ internal class TarsInput(
Tars.LIST -> { // list Tars.LIST -> { // list
debugLogger.structureHierarchy++ debugLogger.structureHierarchy++
repeat(readInt32(0).also { repeat(readInt32(0).also {
println("SIZE = $it") debugLogger.println("SIZE = $it")
}) { }) {
skipField(nextHead().type) skipField(nextHead().type)
} }
@ -218,7 +218,7 @@ internal class TarsInput(
// region readers // region readers
fun readTarsIntValue(head: TarsHead): Int { fun readTarsIntValue(head: TarsHead): Int {
//println("readTarsIntValue: $head") //debugLogger.println("readTarsIntValue: $head")
return readTarsIntValue(head.type, head) return readTarsIntValue(head.type, head)
} }
@ -254,7 +254,7 @@ internal class TarsInput(
} }
fun readTarsByteValue(head: TarsHead): Byte { fun readTarsByteValue(head: TarsHead): Byte {
//println("readTarsByteValue: $head") //debugLogger.println("readTarsByteValue: $head")
return when (head.type) { return when (head.type) {
Tars.ZERO_TYPE -> 0 Tars.ZERO_TYPE -> 0
Tars.BYTE -> input.readByte() Tars.BYTE -> input.readByte()
@ -272,7 +272,7 @@ internal class TarsInput(
@OptIn(ExperimentalUnsignedTypes::class) @OptIn(ExperimentalUnsignedTypes::class)
fun readTarsStringValue(head: TarsHead): String { fun readTarsStringValue(head: TarsHead): String {
//println("readTarsStringValue: $head") //debugLogger.println("readTarsStringValue: $head")
return when (head.type) { return when (head.type) {
Tars.STRING1 -> input.readString(input.readUByte().toInt(), charset = charset) Tars.STRING1 -> input.readString(input.readUByte().toInt(), charset = charset)
Tars.STRING4 -> input.readString( Tars.STRING4 -> input.readString(