Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
79bb9e7d
Commit
79bb9e7d
authored
Mar 17, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add detailed error message
parent
0407b99a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
23 deletions
+40
-23
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
.../mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
+8
-4
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/common.kt
.../net/mamoe/mirai/qqandroid/io/serialization/jce/common.kt
+32
-19
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
View file @
79bb9e7d
...
...
@@ -181,8 +181,9 @@ internal class JceDecoder(
StructureKind
.
MAP
->
{
//println("!! MAP")
return
jce
.
skipToHeadAndUseIfPossibleOrFail
(
popTag
().
id
)
{
it
.
checkType
(
Jce
.
MAP
)
val
tag
=
popTag
()
return
jce
.
skipToHeadAndUseIfPossibleOrFail
(
tag
.
id
)
{
it
.
checkType
(
Jce
.
MAP
,
"beginStructure"
,
tag
,
descriptor
)
MapReader
}
}
...
...
@@ -191,6 +192,8 @@ internal class JceDecoder(
//println("decoderTag: $currentTagOrNull")
//println("jceHead: " + jce.currentHeadOrNull)
return
jce
.
skipToHeadAndUseIfPossibleOrFail
(
currentTag
.
id
)
{
// don't check type. it's polymorphic
//println("listHead: $it")
when
(
it
.
type
)
{
Jce
.
SIMPLE_LIST
->
{
...
...
@@ -209,8 +212,9 @@ internal class JceDecoder(
//println("!! CLASS")
//println("decoderTag: $currentTag")
//println("jceHead: " + jce.currentHeadOrNull)
return
jce
.
skipToHeadAndUseIfPossibleOrFail
(
popTag
().
id
)
{
jceHead
->
jceHead
.
checkType
(
Jce
.
STRUCT_BEGIN
)
val
tag
=
popTag
()
return
jce
.
skipToHeadAndUseIfPossibleOrFail
(
tag
.
id
)
{
jceHead
->
jceHead
.
checkType
(
Jce
.
STRUCT_BEGIN
,
"beginStructure"
,
tag
,
descriptor
)
repeat
(
descriptor
.
elementsCount
)
{
pushTag
(
descriptor
.
getTag
(
descriptor
.
elementsCount
-
it
-
1
))
// better performance
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/common.kt
View file @
79bb9e7d
...
...
@@ -10,6 +10,7 @@
package
net.mamoe.mirai.qqandroid.io.serialization.jce
import
kotlinx.io.core.Output
import
kotlinx.serialization.SerialDescriptor
import
kotlinx.serialization.SerialInfo
...
...
@@ -57,8 +58,15 @@ internal data class JceTagCommon(
override
val
id
:
Int
)
:
JceTag
()
fun
JceHead
.
checkType
(
type
:
Byte
)
{
check
(
this
.
type
==
type
)
{
"type mismatch. Expected $type, actual ${this.type}"
}
internal
fun
JceHead
.
checkType
(
type
:
Byte
,
message
:
String
,
tag
:
JceTag
,
descriptor
:
SerialDescriptor
)
{
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
...
...
@@ -83,23 +91,28 @@ inline class JceHead(private val value: Long) {
val
type
:
Byte
get
()
=
value
.
toUInt
().
toByte
()
override
fun
toString
():
String
{
val
typeString
=
when
(
type
)
{
Jce
.
BYTE
->
"Byte"
Jce
.
DOUBLE
->
"Double"
Jce
.
FLOAT
->
"Float"
Jce
.
INT
->
"Int"
Jce
.
LIST
->
"List"
Jce
.
LONG
->
"Long"
Jce
.
MAP
->
"Map"
Jce
.
SHORT
->
"Short"
Jce
.
SIMPLE_LIST
->
"SimpleList"
Jce
.
STRING1
->
"String1"
Jce
.
STRING4
->
"String4"
Jce
.
STRUCT_BEGIN
->
"StructBegin"
Jce
.
STRUCT_END
->
"StructEnd"
Jce
.
ZERO_TYPE
->
"Zero"
else
->
error
(
"illegal jce type: $type"
)
return
"JceHead(tag=$tag, type=$type(${findJceTypeName(type)}))"
}
companion
object
{
fun
findJceTypeName
(
type
:
Byte
):
String
{
return
when
(
type
)
{
Jce
.
BYTE
->
"Byte"
Jce
.
DOUBLE
->
"Double"
Jce
.
FLOAT
->
"Float"
Jce
.
INT
->
"Int"
Jce
.
LIST
->
"List"
Jce
.
LONG
->
"Long"
Jce
.
MAP
->
"Map"
Jce
.
SHORT
->
"Short"
Jce
.
SIMPLE_LIST
->
"SimpleList"
Jce
.
STRING1
->
"String1"
Jce
.
STRING4
->
"String4"
Jce
.
STRUCT_BEGIN
->
"StructBegin"
Jce
.
STRUCT_END
->
"StructEnd"
Jce
.
ZERO_TYPE
->
"Zero"
else
->
error
(
"illegal jce type: $type"
)
}
}
return
"JceHead(tag=$tag, type=$type($typeString))"
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment