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
24983d8b
Commit
24983d8b
authored
Mar 06, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throws EOFException rather than IllegalStateException
parent
115ccec9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
20 deletions
+38
-20
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
.../mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
+8
-8
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/JceInput.kt
...et/mamoe/mirai/qqandroid/io/serialization/jce/JceInput.kt
+14
-12
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/common.kt
.../net/mamoe/mirai/qqandroid/io/serialization/jce/common.kt
+16
-0
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
View file @
24983d8b
...
@@ -45,28 +45,28 @@ private class JceDecoder(
...
@@ -45,28 +45,28 @@ private class JceDecoder(
}
}
override
fun
decodeTaggedInt
(
tag
:
JceTag
):
Int
=
override
fun
decodeTaggedInt
(
tag
:
JceTag
):
Int
=
jce
.
skipTo
Tag
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceIntValue
(
it
)
}
jce
.
skipTo
Head
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceIntValue
(
it
)
}
override
fun
decodeTaggedByte
(
tag
:
JceTag
):
Byte
=
override
fun
decodeTaggedByte
(
tag
:
JceTag
):
Byte
=
jce
.
skipTo
Tag
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceByteValue
(
it
)
}
jce
.
skipTo
Head
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceByteValue
(
it
)
}
override
fun
decodeTaggedBoolean
(
tag
:
JceTag
):
Boolean
=
override
fun
decodeTaggedBoolean
(
tag
:
JceTag
):
Boolean
=
jce
.
skipTo
Tag
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceBooleanValue
(
it
)
}
jce
.
skipTo
Head
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceBooleanValue
(
it
)
}
override
fun
decodeTaggedFloat
(
tag
:
JceTag
):
Float
=
override
fun
decodeTaggedFloat
(
tag
:
JceTag
):
Float
=
jce
.
skipTo
Tag
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceFloatValue
(
it
)
}
jce
.
skipTo
Head
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceFloatValue
(
it
)
}
override
fun
decodeTaggedDouble
(
tag
:
JceTag
):
Double
=
override
fun
decodeTaggedDouble
(
tag
:
JceTag
):
Double
=
jce
.
skipTo
Tag
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceDoubleValue
(
it
)
}
jce
.
skipTo
Head
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceDoubleValue
(
it
)
}
override
fun
decodeTaggedShort
(
tag
:
JceTag
):
Short
=
override
fun
decodeTaggedShort
(
tag
:
JceTag
):
Short
=
jce
.
skipTo
Tag
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceShortValue
(
it
)
}
jce
.
skipTo
Head
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceShortValue
(
it
)
}
override
fun
decodeTaggedLong
(
tag
:
JceTag
):
Long
=
override
fun
decodeTaggedLong
(
tag
:
JceTag
):
Long
=
jce
.
skipTo
Tag
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceLongValue
(
it
)
}
jce
.
skipTo
Head
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceLongValue
(
it
)
}
override
fun
decodeTaggedString
(
tag
:
JceTag
):
String
=
override
fun
decodeTaggedString
(
tag
:
JceTag
):
String
=
jce
.
skipTo
Tag
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceStringValue
(
it
)
}
jce
.
skipTo
Head
AndUseIfPossibleOrFail
(
tag
.
id
)
{
jce
.
readJceStringValue
(
it
)
}
override
fun
decodeTaggedEnum
(
tag
:
JceTag
,
enumDescription
:
SerialDescriptor
):
Int
{
override
fun
decodeTaggedEnum
(
tag
:
JceTag
,
enumDescription
:
SerialDescriptor
):
Int
{
return
super
.
decodeTaggedEnum
(
tag
,
enumDescription
)
return
super
.
decodeTaggedEnum
(
tag
,
enumDescription
)
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/JceInput.kt
View file @
24983d8b
...
@@ -23,7 +23,7 @@ class JceInput(
...
@@ -23,7 +23,7 @@ class JceInput(
)
{
)
{
private
var
_head
:
JceHead
?
=
null
private
var
_head
:
JceHead
?
=
null
val
currentHead
:
JceHead
get
()
=
_head
?:
error
(
"No current JceHead available"
)
val
currentHead
:
JceHead
get
()
=
_head
?:
throw
EOFException
(
"No current JceHead available"
)
val
currentHeadOrNull
:
JceHead
?
get
()
=
_head
val
currentHeadOrNull
:
JceHead
?
get
()
=
_head
init
{
init
{
...
@@ -40,7 +40,9 @@ class JceInput(
...
@@ -40,7 +40,9 @@ class JceInput(
}
}
fun
nextHead
():
JceHead
{
fun
nextHead
():
JceHead
{
check
(
prepareNextHead
())
{
"No more JceHead available"
}
if
(!
prepareNextHead
())
{
throw
EOFException
(
"No more JceHead available"
)
}
return
currentHead
return
currentHead
}
}
...
@@ -51,13 +53,13 @@ class JceInput(
...
@@ -51,13 +53,13 @@ class JceInput(
@Suppress
(
"FunctionName"
)
@Suppress
(
"FunctionName"
)
@OptIn
(
ExperimentalUnsignedTypes
::
class
)
@OptIn
(
ExperimentalUnsignedTypes
::
class
)
private
fun
readNextHeadButDoNotAssignTo_Head
():
JceHead
?
{
private
fun
readNextHeadButDoNotAssignTo_Head
():
JceHead
?
{
if
(
input
.
endOfInput
)
{
return
null
}
val
var2
=
input
.
readUByte
()
val
var2
=
input
.
readUByte
()
val
type
=
var2
and
15
u
val
type
=
var2
and
15
u
var
tag
=
var2
.
toUInt
()
shr
4
var
tag
=
var2
.
toUInt
()
shr
4
if
(
tag
==
15
u
)
{
if
(
tag
==
15
u
)
{
if
(
input
.
endOfInput
)
{
return
null
}
tag
=
input
.
readUByte
().
toUInt
()
tag
=
input
.
readUByte
().
toUInt
()
}
}
return
JceHead
(
return
JceHead
(
...
@@ -77,19 +79,19 @@ class JceInput(
...
@@ -77,19 +79,19 @@ class JceInput(
/**
/**
* 跳过 [JceHead] 和对应的数据值, 直到找到 [tag], 否则返回 `null`
* 跳过 [JceHead] 和对应的数据值, 直到找到 [tag], 否则返回 `null`
*/
*/
inline
fun
<
R
>
skipTo
Tag
AndUseIfPossibleOrNull
(
tag
:
Int
,
crossinline
block
:
(
JceHead
)
->
R
):
R
?
{
inline
fun
<
R
>
skipTo
Head
AndUseIfPossibleOrNull
(
tag
:
Int
,
crossinline
block
:
(
JceHead
)
->
R
):
R
?
{
return
skipToHeadOrNull
(
tag
)
?.
let
(
block
).
also
{
prepareNextHead
()
}
return
skipToHeadOrNull
(
tag
)
?.
let
(
block
).
also
{
prepareNextHead
()
}
}
}
/**
/**
* 跳过 [JceHead] 和对应的数据值, 直到找到 [tag], 否则抛出异常
* 跳过 [JceHead] 和对应的数据值, 直到找到 [tag], 否则抛出异常
*/
*/
inline
fun
<
R
:
Any
>
skipTo
Tag
AndUseIfPossibleOrFail
(
inline
fun
<
R
:
Any
>
skipTo
Head
AndUseIfPossibleOrFail
(
tag
:
Int
,
tag
:
Int
,
crossinline
message
:
()
->
String
=
{
"tag not found: $tag"
},
crossinline
message
:
()
->
String
=
{
"tag not found: $tag"
},
crossinline
block
:
(
JceHead
)
->
R
crossinline
block
:
(
JceHead
)
->
R
):
R
{
):
R
{
return
checkNotNull
<
R
>(
skipTo
Tag
AndUseIfPossibleOrNull
(
tag
,
block
),
message
)
return
checkNotNull
<
R
>(
skipTo
Head
AndUseIfPossibleOrNull
(
tag
,
block
),
message
)
}
}
tailrec
fun
skipToHeadOrNull
(
tag
:
Int
):
JceHead
?
{
tailrec
fun
skipToHeadOrNull
(
tag
:
Int
):
JceHead
?
{
...
@@ -125,14 +127,14 @@ class JceInput(
...
@@ -125,14 +127,14 @@ class JceInput(
Jce
.
STRING1
->
this
.
input
.
discardExact
(
this
.
input
.
readUByte
().
toInt
())
Jce
.
STRING1
->
this
.
input
.
discardExact
(
this
.
input
.
readUByte
().
toInt
())
Jce
.
STRING4
->
this
.
input
.
discardExact
(
this
.
input
.
readInt
())
Jce
.
STRING4
->
this
.
input
.
discardExact
(
this
.
input
.
readInt
())
Jce
.
MAP
->
{
// map
Jce
.
MAP
->
{
// map
repeat
(
skipTo
Tag
AndUseIfPossibleOrFail
(
0
)
{
repeat
(
skipTo
Head
AndUseIfPossibleOrFail
(
0
)
{
readJceIntValue
(
it
)
readJceIntValue
(
it
)
}
*
2
)
{
}
*
2
)
{
useHead
{
skipField
(
it
.
type
)
}
useHead
{
skipField
(
it
.
type
)
}
}
}
}
}
Jce
.
LIST
->
{
// list
Jce
.
LIST
->
{
// list
repeat
(
skipTo
Tag
AndUseIfPossibleOrFail
(
0
)
{
repeat
(
skipTo
Head
AndUseIfPossibleOrFail
(
0
)
{
readJceIntValue
(
it
)
readJceIntValue
(
it
)
})
{
})
{
useHead
{
skipField
(
it
.
type
)
}
useHead
{
skipField
(
it
.
type
)
}
...
@@ -155,7 +157,7 @@ class JceInput(
...
@@ -155,7 +157,7 @@ class JceInput(
val
head
=
nextHead
()
val
head
=
nextHead
()
check
(
head
.
type
.
toInt
()
==
0
)
{
"skipField with invalid type, type value: "
+
type
+
", "
+
head
.
type
}
check
(
head
.
type
.
toInt
()
==
0
)
{
"skipField with invalid type, type value: "
+
type
+
", "
+
head
.
type
}
this
.
input
.
discardExact
(
this
.
input
.
discardExact
(
skipTo
Tag
AndUseIfPossibleOrFail
(
0
)
{
skipTo
Head
AndUseIfPossibleOrFail
(
0
)
{
readJceIntValue
(
it
)
readJceIntValue
(
it
)
}
}
)
)
...
@@ -232,6 +234,6 @@ class JceInput(
...
@@ -232,6 +234,6 @@ class JceInput(
}
}
fun
readJceBooleanValue
(
head
:
JceHead
):
Boolean
{
fun
readJceBooleanValue
(
head
:
JceHead
):
Boolean
{
return
readJceByteValue
(
head
)
==
0
.
toByte
()
return
readJceByteValue
(
head
)
==
1
.
toByte
()
}
}
}
}
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/common.kt
View file @
24983d8b
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
package
net.mamoe.mirai.qqandroid.io.serialization.jce
package
net.mamoe.mirai.qqandroid.io.serialization.jce
import
io.ktor.utils.io.core.Output
import
kotlinx.serialization.SerialInfo
import
kotlinx.serialization.SerialInfo
import
net.mamoe.mirai.qqandroid.io.serialization.Jce
import
net.mamoe.mirai.qqandroid.io.serialization.Jce
...
@@ -24,12 +25,27 @@ annotation class JceId(val id: Int)
...
@@ -24,12 +25,27 @@ annotation class JceId(val id: Int)
*
*
* 保留这个结构, 为将来增加功能的兼容性.
* 保留这个结构, 为将来增加功能的兼容性.
*/
*/
@PublishedApi
internal
data class
JceTag
(
internal
data class
JceTag
(
val
id
:
Int
,
val
id
:
Int
,
val
isNullable
:
Boolean
val
isNullable
:
Boolean
)
)
@PublishedApi
internal
fun
Output
.
writeJceHead
(
type
:
Byte
,
tag
:
Int
)
{
if
(
tag
<
15
)
{
writeByte
(((
tag
shl
4
)
or
type
.
toInt
()).
toByte
())
return
}
if
(
tag
<
256
)
{
writeByte
((
type
.
toInt
()
or
0
xF0
).
toByte
())
writeByte
(
tag
.
toByte
())
return
}
error
(
"tag is too large: $tag"
)
}
@OptIn
(
ExperimentalUnsignedTypes
::
class
)
@OptIn
(
ExperimentalUnsignedTypes
::
class
)
inline
class
JceHead
(
private
val
value
:
Long
)
{
inline
class
JceHead
(
private
val
value
:
Long
)
{
constructor
(
tag
:
Int
,
type
:
Byte
)
:
this
(
tag
.
toLong
().
shl
(
32
)
or
type
.
toLong
())
constructor
(
tag
:
Int
,
type
:
Byte
)
:
this
(
tag
.
toLong
().
shl
(
32
)
or
type
.
toLong
())
...
...
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