mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 07:30:09 +08:00
Fix TarsInput.skipField
This commit is contained in:
parent
1eecefd16e
commit
fce2ac469e
@ -12,6 +12,7 @@ package net.mamoe.mirai.internal.utils.io.serialization.tars.internal
|
|||||||
import kotlinx.io.charsets.Charset
|
import kotlinx.io.charsets.Charset
|
||||||
import kotlinx.io.core.*
|
import kotlinx.io.core.*
|
||||||
import net.mamoe.mirai.internal.utils.io.serialization.tars.Tars
|
import net.mamoe.mirai.internal.utils.io.serialization.tars.Tars
|
||||||
|
import net.mamoe.mirai.internal.utils.io.serialization.tars.internal.TarsDecoder.Companion.println
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,7 +111,7 @@ internal class TarsInput(
|
|||||||
@OptIn(ExperimentalUnsignedTypes::class)
|
@OptIn(ExperimentalUnsignedTypes::class)
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun skipField(type: Byte) {
|
internal fun skipField(type: Byte) {
|
||||||
TarsDecoder.println {
|
println {
|
||||||
"skipping ${
|
"skipping ${
|
||||||
TarsHead.findTarsTypeName(
|
TarsHead.findTarsTypeName(
|
||||||
type
|
type
|
||||||
@ -128,32 +129,17 @@ internal class TarsInput(
|
|||||||
Tars.STRING4 -> this.input.discardExact(this.input.readInt())
|
Tars.STRING4 -> this.input.discardExact(this.input.readInt())
|
||||||
Tars.MAP -> { // map
|
Tars.MAP -> { // map
|
||||||
TarsDecoder.structureHierarchy++
|
TarsDecoder.structureHierarchy++
|
||||||
var count = 0
|
val sizeHead = nextHead()
|
||||||
nextHead() // avoid shadowing, don't remove
|
repeat(readTarsIntValue(sizeHead)) {
|
||||||
repeat(skipToHeadAndUseIfPossibleOrFail(0, message = { "tag 0 not found when skipping map" }) { head ->
|
skipField(nextHead().type)
|
||||||
readTarsIntValue(head).also { count = it * 2 }
|
|
||||||
} * 2) {
|
|
||||||
skipField(currentHead.type)
|
|
||||||
if (it != count - 1) { // don't read last head
|
|
||||||
nextHead()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
TarsDecoder.structureHierarchy--
|
TarsDecoder.structureHierarchy--
|
||||||
}
|
}
|
||||||
Tars.LIST -> { // list
|
Tars.LIST -> { // list
|
||||||
TarsDecoder.structureHierarchy++
|
TarsDecoder.structureHierarchy++
|
||||||
var count = 0
|
val sizeHead = nextHead()
|
||||||
nextHead() // avoid shadowing, don't remove
|
repeat(readTarsIntValue(sizeHead) * 2) {
|
||||||
repeat(skipToHeadAndUseIfPossibleOrFail(0, message = { "tag 0 not found when skipping list" }) { head ->
|
skipField(nextHead().type)
|
||||||
readTarsIntValue(head).also { count = it }
|
|
||||||
}) {
|
|
||||||
skipField(currentHead.type)
|
|
||||||
if (it != count - 1) { // don't read last head
|
|
||||||
nextHead()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count == 0) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
TarsDecoder.structureHierarchy--
|
TarsDecoder.structureHierarchy--
|
||||||
}
|
}
|
||||||
@ -162,9 +148,13 @@ internal class TarsInput(
|
|||||||
var head: TarsHead
|
var head: TarsHead
|
||||||
do {
|
do {
|
||||||
head = nextHead()
|
head = nextHead()
|
||||||
|
if (head.type == Tars.STRUCT_END) {
|
||||||
|
TarsDecoder.structureHierarchy--
|
||||||
|
skipField(head.type)
|
||||||
|
break
|
||||||
|
}
|
||||||
skipField(head.type)
|
skipField(head.type)
|
||||||
} while (head.type != Tars.STRUCT_END)
|
} while (head.type != Tars.STRUCT_END)
|
||||||
TarsDecoder.structureHierarchy--
|
|
||||||
}
|
}
|
||||||
Tars.STRUCT_END, Tars.ZERO_TYPE -> {
|
Tars.STRUCT_END, Tars.ZERO_TYPE -> {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user