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
472da8d3
Commit
472da8d3
authored
Mar 06, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
List support
parent
37344c19
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
8 deletions
+84
-8
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
.../mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
+43
-8
mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceInputTest.kt
...et.mamoe.mirai.qqandroid.io.serialization/JceInputTest.kt
+41
-0
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/io/serialization/jce/JceDecoder.kt
View file @
472da8d3
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
package
net.mamoe.mirai.qqandroid.io.serialization.jce
package
net.mamoe.mirai.qqandroid.io.serialization.jce
import
kotlinx.serialization.*
import
kotlinx.serialization.*
import
kotlinx.serialization.builtins.AbstractDecoder
import
kotlinx.serialization.builtins.ByteArraySerializer
import
kotlinx.serialization.builtins.ByteArraySerializer
import
kotlinx.serialization.internal.TaggedDecoder
import
kotlinx.serialization.internal.TaggedDecoder
import
kotlinx.serialization.modules.SerialModule
import
kotlinx.serialization.modules.SerialModule
...
@@ -46,13 +47,29 @@ internal class JceDecoder(
...
@@ -46,13 +47,29 @@ internal class JceDecoder(
}
}
// TODO: 2020/3/6 can be object
// TODO: 2020/3/6 can be object
private
inner
class
SimpleByteArrayReader
:
CompositeDecoder
by
this
{
private
inner
class
SimpleByteArrayReader
:
AbstractDecoder
()
{
override
fun
decodeSequentially
():
Boolean
=
true
override
fun
decodeSequentially
():
Boolean
=
true
override
fun
decodeByteElement
(
descriptor
:
SerialDescriptor
,
index
:
Int
):
Byte
{
println
(
"decodeByteElement: $index"
)
override
fun
endStructure
(
descriptor
:
SerialDescriptor
)
{
return
jce
.
input
.
readByte
().
also
{
println
(
"read: $it"
)
}
this
@JceDecoder
.
endStructure
(
descriptor
)
}
override
fun
beginStructure
(
descriptor
:
SerialDescriptor
,
vararg
typeParams
:
KSerializer
<
*
>):
CompositeDecoder
{
this
@JceDecoder
.
pushTag
(
JceTag
(
0
,
false
))
return
this
@JceDecoder
.
beginStructure
(
descriptor
,
*
typeParams
)
}
}
override
fun
decodeByte
():
Byte
=
jce
.
input
.
readByte
().
also
{
println
(
"decodeByte: $it"
)
}
override
fun
decodeShort
():
Short
=
error
(
"illegal access"
)
override
fun
decodeInt
():
Int
=
error
(
"illegal access"
)
override
fun
decodeLong
():
Long
=
error
(
"illegal access"
)
override
fun
decodeFloat
():
Float
=
error
(
"illegal access"
)
override
fun
decodeDouble
():
Double
=
error
(
"illegal access"
)
override
fun
decodeBoolean
():
Boolean
=
error
(
"illegal access"
)
override
fun
decodeChar
():
Char
=
error
(
"illegal access"
)
override
fun
decodeEnum
(
enumDescriptor
:
SerialDescriptor
):
Int
=
error
(
"illegal access"
)
override
fun
decodeString
():
String
=
error
(
"illegal access"
)
override
fun
decodeElementIndex
(
descriptor
:
SerialDescriptor
):
Int
{
override
fun
decodeElementIndex
(
descriptor
:
SerialDescriptor
):
Int
{
error
(
"should not be reached"
)
error
(
"should not be reached"
)
}
}
...
@@ -64,23 +81,41 @@ internal class JceDecoder(
...
@@ -64,23 +81,41 @@ internal class JceDecoder(
}
}
// TODO: 2020/3/6 can be object
// TODO: 2020/3/6 can be object
private
inner
class
ListReader
:
CompositeDecoder
by
this
{
private
inner
class
ListReader
:
AbstractDecoder
()
{
override
fun
decodeSequentially
():
Boolean
=
true
override
fun
decodeSequentially
():
Boolean
=
true
override
fun
decodeElementIndex
(
descriptor
:
SerialDescriptor
):
Int
=
error
(
"should not be reached"
)
override
fun
decodeElementIndex
(
descriptor
:
SerialDescriptor
):
Int
=
error
(
"should not be reached"
)
override
fun
endStructure
(
descriptor
:
SerialDescriptor
)
{
override
fun
endStructure
(
descriptor
:
SerialDescriptor
)
{
println
(
"endStructure: ${descriptor.serialName}"
)
this
@JceDecoder
.
endStructure
(
descriptor
)
}
}
override
fun
beginStructure
(
descriptor
:
SerialDescriptor
,
vararg
typeParams
:
KSerializer
<
*
>):
CompositeDecoder
{
this
@JceDecoder
.
pushTag
(
JceTag
(
0
,
false
))
return
this
@JceDecoder
.
beginStructure
(
descriptor
,
*
typeParams
)
}
override
fun
decodeByte
():
Byte
=
jce
.
useHead
{
jce
.
readJceByteValue
(
it
)
}
override
fun
decodeShort
():
Short
=
jce
.
useHead
{
jce
.
readJceShortValue
(
it
)
}
override
fun
decodeInt
():
Int
=
jce
.
useHead
{
jce
.
readJceIntValue
(
it
)
}
override
fun
decodeLong
():
Long
=
jce
.
useHead
{
jce
.
readJceLongValue
(
it
)
}
override
fun
decodeFloat
():
Float
=
jce
.
useHead
{
jce
.
readJceFloatValue
(
it
)
}
override
fun
decodeDouble
():
Double
=
jce
.
useHead
{
jce
.
readJceDoubleValue
(
it
)
}
override
fun
decodeBoolean
():
Boolean
=
jce
.
useHead
{
jce
.
readJceBooleanValue
(
it
)
}
override
fun
decodeChar
():
Char
=
decodeByte
().
toChar
()
override
fun
decodeEnum
(
enumDescriptor
:
SerialDescriptor
):
Int
=
decodeInt
()
override
fun
decodeString
():
String
=
jce
.
useHead
{
jce
.
readJceStringValue
(
it
)
}
override
fun
decodeCollectionSize
(
descriptor
:
SerialDescriptor
):
Int
{
override
fun
decodeCollectionSize
(
descriptor
:
SerialDescriptor
):
Int
{
println
(
"decodeCollectionSize: ${descriptor.serialName}"
)
// 不读下一个 head
// 不读下一个 head
return
jce
.
currentHead
.
let
{
jce
.
readJceIntValue
(
it
)
}.
also
{
println
(
"listSize=$it"
)
}
return
jce
.
useHead
{
jce
.
readJceIntValue
(
it
)
}.
also
{
println
(
"listSize=$it"
)
}
}
}
}
}
override
fun
endStructure
(
descriptor
:
SerialDescriptor
)
{
override
fun
endStructure
(
descriptor
:
SerialDescriptor
)
{
println
(
"endStructure: $descriptor"
)
if
(
descriptor
==
ByteArraySerializer
.
descriptor
)
{
if
(
descriptor
==
ByteArraySerializer
.
descriptor
)
{
jce
.
prepareNextHead
()
// list 里面没读 head
jce
.
prepareNextHead
()
// list 里面没读 head
}
}
else
jce
.
prepareNextHead
()
// TODO ?? 测试这里
super
.
endStructure
(
descriptor
)
super
.
endStructure
(
descriptor
)
}
}
...
...
mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceInputTest.kt
View file @
472da8d3
...
@@ -40,6 +40,46 @@ internal const val ZERO_TYPE: Byte = 12
...
@@ -40,6 +40,46 @@ internal const val ZERO_TYPE: Byte = 12
@Suppress
(
"INVISIBLE_MEMBER"
)
// bug
@Suppress
(
"INVISIBLE_MEMBER"
)
// bug
internal
class
JceInputTest
{
internal
class
JceInputTest
{
@Test
fun
testNestedList
()
{
@Serializable
data class
TestSerializableClassA
(
// @JceId(0) val byteArray: ByteArray = byteArrayOf(1, 2, 3),
@JceId
(
3
)
val
byteArray2
:
List
<
List
<
Int
>>
=
listOf
(
listOf
(
1
,
2
,
3
,
4
),
listOf
(
1
,
2
,
3
,
4
))
)
val
input
=
buildPacket
{
//writeJceHead(SIMPLE_LIST, 0)
//writeJceHead(BYTE, 0)
//writeJceHead(BYTE, 0)
//byteArrayOf(1, 2, 3).let {
// writeByte(it.size.toByte())
// writeFully(it)
//}
writeJceHead
(
LIST
,
3
)
writeJceHead
(
BYTE
,
0
)
writeByte
(
2
)
listOf
(
listOf
(
1
,
2
,
3
,
4
),
listOf
(
1
,
2
,
3
,
4
)).
forEach
{
writeJceHead
(
LIST
,
0
)
writeJceHead
(
BYTE
,
0
)
writeByte
(
it
.
size
.
toByte
())
it
.
forEach
{
writeJceHead
(
INT
,
0
)
writeInt
(
it
)
}
}
}
assertEquals
(
TestSerializableClassA
(),
JceNew
.
UTF_8
.
load
(
TestSerializableClassA
.
serializer
(),
input
))
}
@Test
@Test
fun
testSimpleByteArray
()
{
fun
testSimpleByteArray
()
{
@Serializable
@Serializable
...
@@ -58,6 +98,7 @@ internal class JceInputTest {
...
@@ -58,6 +98,7 @@ internal class JceInputTest {
return
true
return
true
}
}
override
fun
hashCode
():
Int
{
override
fun
hashCode
():
Int
{
var
result
=
byteArray
.
contentHashCode
()
var
result
=
byteArray
.
contentHashCode
()
result
=
31
*
result
+
byteArray2
.
hashCode
()
result
=
31
*
result
+
byteArray2
.
hashCode
()
...
...
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