fix #85 lynon empty list encoding
This commit is contained in:
parent
bfffea7e69
commit
678cfbf45e
@ -127,9 +127,11 @@ open class LynonEncoder(val bout: BitOutput, val settings: LynonSettings = Lynon
|
|||||||
*/
|
*/
|
||||||
suspend fun encodeAnyList(scope: Scope, list: List<Obj>,fixedSize: Boolean = false) {
|
suspend fun encodeAnyList(scope: Scope, list: List<Obj>,fixedSize: Boolean = false) {
|
||||||
if( list.isEmpty()) {
|
if( list.isEmpty()) {
|
||||||
// any-typed, empty, save space
|
// Empty list: we still need to write the heterogenous/homogenous flag bit
|
||||||
putBit(0)
|
// but must NOT write the size when fixedSize is provided, as decoder will
|
||||||
encodeUnsigned(0u)
|
// use the provided size and won't read it from the stream.
|
||||||
|
putBit(0) // treat empty lists as heterogeneous
|
||||||
|
if (!fixedSize) encodeUnsigned(0u)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val objClass = list[0].objClass
|
val objClass = list[0].objClass
|
||||||
|
|||||||
@ -4013,6 +4013,13 @@ class ScriptTest {
|
|||||||
assertEquals( TestJson4(TestEnum.One), x)
|
assertEquals( TestJson4(TestEnum.One), x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testStringLast() = runTest {
|
||||||
|
eval("""
|
||||||
|
assertEquals('t', "assert".last())
|
||||||
|
""".trimIndent())
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLogicalNot() = runTest {
|
fun testLogicalNot() = runTest {
|
||||||
eval("""
|
eval("""
|
||||||
|
|||||||
@ -778,6 +778,19 @@ class Wallet( id, ownerKey, balance=0, createdAt=Instant.now().truncateToSecond(
|
|||||||
assert( Lynon.encode(Poin3(1,2)).size <= 110)
|
assert( Lynon.encode(Poin3(1,2)).size <= 110)
|
||||||
""".trimIndent())
|
""".trimIndent())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testLyngDecodeResult() = runTest {
|
||||||
|
val a = eval("""
|
||||||
|
[Map(),Map(),Map()]
|
||||||
|
""".trimIndent())
|
||||||
|
val b = lynonDecodeAny(Scope(), lynonEncodeAny(Scope(), a))
|
||||||
|
assertEquals(a, b )
|
||||||
|
// val c = b.decodeSerializable<JsonElement>()
|
||||||
|
// println(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user