BiPack: added @FixedSize for collection serialization
This commit is contained in:
1 parent
bd19570dec
commit
204f73f045
6 files changed
+156
-91
No files matched your search
@@ -5,7 +5,10 @@ import kotlinx.serialization.Serializable
|
||||
import net.sergeych.bintools.toDump
|
||||
import net.sergeych.bipack.*
|
||||
import kotlin.experimental.xor
|
||||
import kotlin.test.*
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
@Serializable
|
||||
data class Foobar1N(val bar: Int, val foo: Int = 117)
|
||||
@@ -114,7 +117,7 @@ class BipackEncoderTest {
|
||||
val u: UInt,
|
||||
@Unsigned
|
||||
val i: Int,
|
||||
val k: UInt = 3u,
|
||||
val k: Int = 3,
|
||||
)
|
||||
|
||||
@Test
|
||||
@@ -215,6 +218,28 @@ class BipackEncoderTest {
|
||||
// println(d.decodeFromBipack<Types1>())
|
||||
assertEquals(t1, t2)
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Fixa(
|
||||
@FixedSize(5)
|
||||
val x: ByteArray
|
||||
)
|
||||
|
||||
@Test
|
||||
fun textFixed() {
|
||||
val x = byteArrayOf(1,2,3,4,5)
|
||||
//@Fixed(32)
|
||||
val y = Fixa(byteArrayOf(1,2,3,4,5))
|
||||
val d1 = BipackEncoder.encode(x)
|
||||
println(d1.toDump())
|
||||
assertEquals(6, d1.size)
|
||||
val d2 = BipackEncoder.encode(y)
|
||||
println(d2.toDump())
|
||||
assertEquals(5, d2.size)
|
||||
assertContentEquals(x, BipackDecoder.decode<ByteArray>(d1))
|
||||
assertContentEquals(x, BipackDecoder.decode<Fixa>(d2).x)
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
fun testMaps() {
|
||||
|
||||
Reference in new issue
Block a user