CRC-protected frames
This commit is contained in:
1 parent
ee2c958445
commit
8c73ec9e30
8 files changed
+155
-27
No files matched your search
@@ -4,6 +4,7 @@ import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import net.sergeych.bintools.toDump
|
||||
import net.sergeych.bipack.*
|
||||
import kotlin.experimental.xor
|
||||
import kotlin.test.*
|
||||
|
||||
@Serializable
|
||||
@@ -31,6 +32,12 @@ data class FoobarF2(val bar: Int, val foo: Int,val other: Int = -1)
|
||||
@ExtendableFormat
|
||||
data class FoobarF3(val bar: Int, val foo: Int,val other: Int = -1)
|
||||
|
||||
@Serializable
|
||||
@Framed
|
||||
@ExtendableFormat
|
||||
@CrcProtected()
|
||||
data class FoobarFP1(val bar: Int, val foo: Int,val other: Int = -1)
|
||||
|
||||
class BipackEncoderTest {
|
||||
|
||||
@Test
|
||||
@@ -64,4 +71,29 @@ class BipackEncoderTest {
|
||||
val b = BipackDecoder.decode<Foobar1N>(BipackEncoder.encode(a))
|
||||
assertEquals(a, b)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun encodeProtectedFrame() {
|
||||
val a = FoobarFP1(42, 117)//, "bum")
|
||||
println(BipackEncoder.encode(a).toDump())
|
||||
val b = BipackDecoder.decode<FoobarFP1>(BipackEncoder.encode(a))
|
||||
assertEquals(a, b)
|
||||
val bad = BipackEncoder.encode(a)
|
||||
bad[6] = bad[6] xor 0x20
|
||||
println(bad.toDump())
|
||||
assertFailsWith(InvalidFrameCRCException::class) {
|
||||
BipackDecoder.decode<FoobarFP1>(bad)
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class FBU(val u: UInt, val i: Int)
|
||||
@Test
|
||||
fun testByteArray() {
|
||||
val x = byteArrayOf(1,2,3)
|
||||
println(BipackEncoder.encode(x).toDump())
|
||||
println(BipackEncoder.encode("123").toDump())
|
||||
println(BipackEncoder.encode(FBU(3u, 3)).toDump())
|
||||
// println(BipackEncoder.encode(1U).toDump())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user