0.0.4-rc: fixed a bug in variable-size short field (rare situation and most often masked).

This commit is contained in:
sergeych committed 2023-10-07 01:50:26 +01:00
1 parent b7784fec18
commit e1c78e2bbb
4 files changed
+63 -5

No files matched your search

@@ -65,4 +65,14 @@ class SmartintTest {
}
}
@Test
fun testCustom() {
val x = 64000.toULong()
val p = Smartint.encodeUnsigned(x)
println(p.toDump())
val y = Smartint.decodeUnsigned(p)
println(y)
assertEquals(y, x)
}
}
@@ -7,6 +7,7 @@ import kotlinx.serialization.Serializable
import net.sergeych.bintools.encodeToHex
import net.sergeych.bintools.toDump
import net.sergeych.bipack.*
import net.sergeych.mp_tools.encodeToBase64Compact
import kotlin.experimental.xor
import kotlin.test.Test
import kotlin.test.assertContentEquals
@@ -314,6 +315,7 @@ class BipackEncoderTest {
@Serializable
data class FU16(@Fixed val i: UShort)
@Serializable
class Foo(
@Fixed
@@ -351,4 +353,47 @@ class BipackEncoderTest {
val y = BipackDecoder.decode<Instant>(BipackEncoder.encode(x))
assertEquals(x.toEpochMilliseconds(), y.toEpochMilliseconds())
}
@Serializable
data class UInts(
val b: UByte,
@Fixed
val si: UShort,
@Fixed
val i: UInt,
@Fixed
val li: ULong
)
@Serializable
data class VarUInts(
val b: UByte,
@Unsigned
val si: UShort,
@Unsigned
val i: UInt,
@Unsigned
val li: ULong
)
@Test
fun vectors() {
val x = UInts(7u, 64000.toUShort(), 66000u, 931127140399u);
val p = BipackEncoder.encode(x);
println(p.toDump())
println(p.encodeToBase64Compact())
val y = BipackDecoder.decode<UInts>(p)
assertEquals(x, y)
val xv = VarUInts(7u, 64000.toUShort(), 66000u, 931127140399u);
val pv = BipackEncoder.encode(xv);
println(pv.toDump())
println(pv.encodeToBase64Compact())
val yv = BipackDecoder.decode<VarUInts>(pv)
assertEquals(xv, yv)
println(xv)
println(yv)
}
}