mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 10:30:13 +08:00
Add detailed error message
This commit is contained in:
parent
0407b99ae2
commit
79bb9e7dc9
@ -181,8 +181,9 @@ internal class JceDecoder(
|
|||||||
|
|
||||||
StructureKind.MAP -> {
|
StructureKind.MAP -> {
|
||||||
//println("!! MAP")
|
//println("!! MAP")
|
||||||
return jce.skipToHeadAndUseIfPossibleOrFail(popTag().id) {
|
val tag = popTag()
|
||||||
it.checkType(Jce.MAP)
|
return jce.skipToHeadAndUseIfPossibleOrFail(tag.id) {
|
||||||
|
it.checkType(Jce.MAP, "beginStructure", tag, descriptor)
|
||||||
MapReader
|
MapReader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,6 +192,8 @@ internal class JceDecoder(
|
|||||||
//println("decoderTag: $currentTagOrNull")
|
//println("decoderTag: $currentTagOrNull")
|
||||||
//println("jceHead: " + jce.currentHeadOrNull)
|
//println("jceHead: " + jce.currentHeadOrNull)
|
||||||
return jce.skipToHeadAndUseIfPossibleOrFail(currentTag.id) {
|
return jce.skipToHeadAndUseIfPossibleOrFail(currentTag.id) {
|
||||||
|
// don't check type. it's polymorphic
|
||||||
|
|
||||||
//println("listHead: $it")
|
//println("listHead: $it")
|
||||||
when (it.type) {
|
when (it.type) {
|
||||||
Jce.SIMPLE_LIST -> {
|
Jce.SIMPLE_LIST -> {
|
||||||
@ -209,8 +212,9 @@ internal class JceDecoder(
|
|||||||
//println("!! CLASS")
|
//println("!! CLASS")
|
||||||
//println("decoderTag: $currentTag")
|
//println("decoderTag: $currentTag")
|
||||||
//println("jceHead: " + jce.currentHeadOrNull)
|
//println("jceHead: " + jce.currentHeadOrNull)
|
||||||
return jce.skipToHeadAndUseIfPossibleOrFail(popTag().id) { jceHead ->
|
val tag = popTag()
|
||||||
jceHead.checkType(Jce.STRUCT_BEGIN)
|
return jce.skipToHeadAndUseIfPossibleOrFail(tag.id) { jceHead ->
|
||||||
|
jceHead.checkType(Jce.STRUCT_BEGIN, "beginStructure", tag, descriptor)
|
||||||
|
|
||||||
repeat(descriptor.elementsCount) {
|
repeat(descriptor.elementsCount) {
|
||||||
pushTag(descriptor.getTag(descriptor.elementsCount - it - 1)) // better performance
|
pushTag(descriptor.getTag(descriptor.elementsCount - it - 1)) // better performance
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
package net.mamoe.mirai.qqandroid.io.serialization.jce
|
package net.mamoe.mirai.qqandroid.io.serialization.jce
|
||||||
|
|
||||||
import kotlinx.io.core.Output
|
import kotlinx.io.core.Output
|
||||||
|
import kotlinx.serialization.SerialDescriptor
|
||||||
import kotlinx.serialization.SerialInfo
|
import kotlinx.serialization.SerialInfo
|
||||||
|
|
||||||
|
|
||||||
@ -57,8 +58,15 @@ internal data class JceTagCommon(
|
|||||||
override val id: Int
|
override val id: Int
|
||||||
) : JceTag()
|
) : JceTag()
|
||||||
|
|
||||||
fun JceHead.checkType(type: Byte) {
|
internal fun JceHead.checkType(type: Byte, message: String, tag: JceTag, descriptor: SerialDescriptor) {
|
||||||
check(this.type == type) { "type mismatch. Expected $type, actual ${this.type}" }
|
check(this.type == type) {
|
||||||
|
"type mismatch. " +
|
||||||
|
"Expected ${JceHead.findJceTypeName(type)}, " +
|
||||||
|
"actual ${JceHead.findJceTypeName(this.type)} for $message. " +
|
||||||
|
"Tag info: " +
|
||||||
|
"id=${tag.id}, " +
|
||||||
|
"name=${descriptor.getElementName(tag.id)} " +
|
||||||
|
"in ${descriptor.serialName}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@ -83,7 +91,12 @@ inline class JceHead(private val value: Long) {
|
|||||||
val type: Byte get() = value.toUInt().toByte()
|
val type: Byte get() = value.toUInt().toByte()
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val typeString = when (type) {
|
return "JceHead(tag=$tag, type=$type(${findJceTypeName(type)}))"
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun findJceTypeName(type: Byte): String {
|
||||||
|
return when (type) {
|
||||||
Jce.BYTE -> "Byte"
|
Jce.BYTE -> "Byte"
|
||||||
Jce.DOUBLE -> "Double"
|
Jce.DOUBLE -> "Double"
|
||||||
Jce.FLOAT -> "Float"
|
Jce.FLOAT -> "Float"
|
||||||
@ -100,6 +113,6 @@ inline class JceHead(private val value: Long) {
|
|||||||
Jce.ZERO_TYPE -> "Zero"
|
Jce.ZERO_TYPE -> "Zero"
|
||||||
else -> error("illegal jce type: $type")
|
else -> error("illegal jce type: $type")
|
||||||
}
|
}
|
||||||
return "JceHead(tag=$tag, type=$type($typeString))"
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user