release 0.1.0: fixed bug with object/empty serialization, migrated to newest kotlin
This commit is contained in:
parent
47b450c597
commit
3e6c487601
@ -2,6 +2,12 @@
|
||||
|
||||
Multiplatform binary tools collection, including portable serialization of the compact and fast [Bipack] format, and many useful tools to work with binary data, like CRC family checksums, dumps, etc. It works well also in the browser and in native targets.
|
||||
|
||||
# Recent changes
|
||||
|
||||
- 0.1.0: uses modern kotlin 1.9.*, fixes problem with singleton or empty/object serialization
|
||||
|
||||
last 1.8 version is 0.0.8, some fixes are not yet backported to it pls leave an issue of needed.
|
||||
|
||||
# Usage
|
||||
|
||||
Add our maven:
|
||||
@ -18,7 +24,7 @@ And add dependecy to the proper place in yuor project like this:
|
||||
```kotlin
|
||||
dependencies {
|
||||
// ...
|
||||
implementation("net.sergeych:mp_bintools:0.0.6")
|
||||
implementation("net.sergeych:mp_bintools:0.1.0")
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
plugins {
|
||||
kotlin("multiplatform") version "1.8.20"
|
||||
kotlin("plugin.serialization") version "1.8.20"
|
||||
id("org.jetbrains.dokka") version "1.6.0"
|
||||
kotlin("multiplatform") version "1.9.22"
|
||||
kotlin("plugin.serialization") version "1.9.22"
|
||||
id("org.jetbrains.dokka") version "1.9.10"
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
val serialization_version = "1.3.4"
|
||||
|
||||
group = "net.sergeych"
|
||||
version = "0.0.7"
|
||||
version = "0.1.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user