release 0.1.0: fixed bug with object/empty serialization, migrated to newest kotlin
This commit is contained in:
1 parent
47b450c597
commit
3e6c487601
5 files changed
+287
-522
No files matched your search
@@ -31,18 +31,20 @@ class BipackDecoder(
|
||||
override fun decodeBoolean(): Boolean = input.readByte().toInt() != 0
|
||||
override fun decodeByte(): Byte = input.readByte()
|
||||
override fun decodeShort(): Short =
|
||||
if( fixedNumber ) input.readI16()
|
||||
if (fixedNumber) input.readI16()
|
||||
else if (nextIsUnsigned)
|
||||
input.readNumber<UInt>().toShort()
|
||||
else
|
||||
input.readNumber()
|
||||
|
||||
override fun decodeInt(): Int =
|
||||
if (fixedNumber) input.readI32()
|
||||
else if (nextIsUnsigned) input.readNumber<UInt>().toInt() else input.readNumber()
|
||||
|
||||
override fun decodeLong(): Long =
|
||||
if( fixedNumber ) input.readI64()
|
||||
if (fixedNumber) input.readI64()
|
||||
else if (nextIsUnsigned) input.readNumber<ULong>().toLong() else input.readNumber()
|
||||
|
||||
override fun decodeFloat(): Float = input.readFloat()
|
||||
override fun decodeDouble(): Double = input.readDouble()
|
||||
override fun decodeChar(): Char = Char(input.readNumber<UInt>().toInt())
|
||||
@@ -57,7 +59,7 @@ class BipackDecoder(
|
||||
override fun decodeEnum(enumDescriptor: SerialDescriptor): Int = input.readNumber<UInt>().toInt()
|
||||
|
||||
override fun decodeElementIndex(descriptor: SerialDescriptor): Int {
|
||||
if (elementIndex >= elementsCount || input.isEnd() == true )
|
||||
if (elementIndex >= elementsCount)
|
||||
return CompositeDecoder.DECODE_DONE
|
||||
nextIsUnsigned = false
|
||||
for (a in descriptor.getElementAnnotations(elementIndex)) {
|
||||
@@ -71,11 +73,13 @@ class BipackDecoder(
|
||||
}
|
||||
|
||||
override fun <T> decodeSerializableValue(deserializer: DeserializationStrategy<T>): T {
|
||||
return if( deserializer == Instant.serializer() )
|
||||
return if (deserializer == Instant.serializer())
|
||||
Instant.fromEpochMilliseconds(decodeLong()) as T
|
||||
else
|
||||
super.decodeSerializableValue(deserializer)
|
||||
}
|
||||
|
||||
|
||||
override fun decodeSequentially(): Boolean = isCollection
|
||||
|
||||
override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder {
|
||||
@@ -122,7 +126,11 @@ class BipackDecoder(
|
||||
super.endStructure(descriptor)
|
||||
}
|
||||
|
||||
override fun decodeNotNullMark(): Boolean = decodeBoolean()
|
||||
override fun decodeNotNullMark(): Boolean = try {
|
||||
decodeBoolean()
|
||||
} catch (_: DataSource.EndOfData) {
|
||||
false
|
||||
}
|
||||
|
||||
@ExperimentalSerializationApi
|
||||
override fun decodeNull(): Nothing? = null
|
||||
|
||||
@@ -46,6 +46,13 @@ data class FoobarF3(val bar: Int, val foo: Int, val other: Int = -1)
|
||||
@CrcProtected()
|
||||
data class FoobarFP1(val bar: Int, val foo: Int, val other: Int = -1)
|
||||
|
||||
@Serializable
|
||||
sealed class SC1 {
|
||||
|
||||
@Serializable
|
||||
class Nested: SC1()
|
||||
}
|
||||
|
||||
class BipackEncoderTest {
|
||||
|
||||
@Serializable
|
||||
@@ -349,7 +356,7 @@ class BipackEncoderTest {
|
||||
@Test
|
||||
fun testInstant() {
|
||||
val x = Clock.System.now()
|
||||
// println( BipackEncoder.encode(x).toDump() )
|
||||
println( BipackEncoder.encode(x).toDump() )
|
||||
val y = BipackDecoder.decode<Instant>(BipackEncoder.encode(x))
|
||||
assertEquals(x.toEpochMilliseconds(), y.toEpochMilliseconds())
|
||||
}
|
||||
@@ -405,4 +412,30 @@ class BipackEncoderTest {
|
||||
println(sf)
|
||||
}
|
||||
|
||||
@Serializable
|
||||
enum class TU1 {
|
||||
N1, N2, N3, N4
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testUnsignedEnums() {
|
||||
val p1 = BipackEncoder.encode(TU1.N4)
|
||||
// val p2 = BipackEncoder.encode(3u)
|
||||
println(p1.toDump())
|
||||
// println(p2.toDump())
|
||||
val t2 = BipackDecoder.decode<TU1>(p1)
|
||||
assertEquals(TU1.N4, t2)
|
||||
assertEquals(0x0cu, p1[0].toUByte())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClosedSerialization() {
|
||||
val x: SC1 = SC1.Nested()
|
||||
val b = BipackEncoder.encode(x)
|
||||
println(b.toDump())
|
||||
val y = BipackDecoder.decode<SC1>(b)
|
||||
println(y)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user