diff --git a/CHANGELOG.md b/CHANGELOG.md index 272cdf894ed..56d200d8902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 0.20.24 + +**Since this version depdendencies of klock and krypto replaced with `com.soywiz.korge:korlibs-time` and `com.soywiz.korge:korlibs-crypto`** + +* `Versions`: + * `Klock` (since now `KorlibsTime`): `4.0.10` -> `5.3.0` + * `Krypto` (since now `KorlibsCrypto`): `4.0.10` -> `5.3.0` +* `Serialization`: + * `Mapper`: + * `Mapper` pass decoder into callback of deserialization strategy + * `Mapper` pass encoder into callback of serialization strategy + ## 0.20.23 * `Versions`: diff --git a/gradle.properties b/gradle.properties index be84a3890cf..d93d99cf483 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.20.23 -android_code_version=229 +version=0.20.24 +android_code_version=230 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 586277f9773..d3185e3bfd2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ jb-compose = "1.5.11" jb-exposed = "0.45.0" jb-dokka = "1.9.10" -korlibs = "4.0.10" +korlibs = "5.3.0" uuid = "0.8.2" ktor = "2.3.7" @@ -21,7 +21,7 @@ koin = "3.5.3" okio = "3.7.0" -ksp = "1.9.22-1.0.16" +ksp = "1.9.21-1.0.16" kotlin-poet = "1.15.3" versions = "0.50.0" @@ -72,8 +72,8 @@ ktor-server-content-negotiation = { module = "io.ktor:ktor-server-content-negoti kslog = { module = "dev.inmo:kslog", version.ref = "kslog" } -klock = { module = "com.soywiz.korlibs.klock:klock", version.ref = "korlibs" } -krypto = { module = "com.soywiz.korlibs.krypto:krypto", version.ref = "korlibs" } +klock = { module = "com.soywiz.korge:korlibs-time", version.ref = "korlibs" } +krypto = { module = "com.soywiz.korge:korlibs-crypto", version.ref = "korlibs" } uuid = { module = "com.benasher44:uuid", version.ref = "uuid" } koin = { module = "io.insert-koin:koin-core", version.ref = "koin" } diff --git a/serialization/mapper/src/commonMain/kotlin/MapperDeserializationStrategy.kt b/serialization/mapper/src/commonMain/kotlin/MapperDeserializationStrategy.kt index bf36ef9fe4b..7bb4b2690b8 100644 --- a/serialization/mapper/src/commonMain/kotlin/MapperDeserializationStrategy.kt +++ b/serialization/mapper/src/commonMain/kotlin/MapperDeserializationStrategy.kt @@ -16,11 +16,16 @@ import kotlinx.serialization.encoding.Encoder */ open class MapperDeserializationStrategy( private val base: DeserializationStrategy, - private val deserialize: (I) -> O + private val deserialize: (Decoder, I) -> O ) : DeserializationStrategy { override val descriptor: SerialDescriptor = base.descriptor + constructor( + base: DeserializationStrategy, + deserialize: (I) -> O + ) : this(base, { _, i -> deserialize(i) }) + override fun deserialize(decoder: Decoder): O { - return deserialize(base.deserialize(decoder)) + return deserialize(decoder, base.deserialize(decoder)) } } diff --git a/serialization/mapper/src/commonMain/kotlin/MapperSerializationStrategy.kt b/serialization/mapper/src/commonMain/kotlin/MapperSerializationStrategy.kt index 4772932915c..e3b5e1a48f8 100644 --- a/serialization/mapper/src/commonMain/kotlin/MapperSerializationStrategy.kt +++ b/serialization/mapper/src/commonMain/kotlin/MapperSerializationStrategy.kt @@ -1,9 +1,7 @@ package dev.inmo.micro_utils.serialization.mapper -import kotlinx.serialization.KSerializer import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.descriptors.SerialDescriptor -import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder /** @@ -11,15 +9,20 @@ import kotlinx.serialization.encoding.Encoder * serialization * * @param base Serializer for [I] - * @param serialize Will be used in [serialize] method to convert incoming [O] to [I] and serialize with [base] + * @param internalSerialize Will be used in [internalSerialize] method to convert incoming [O] to [I] and serialize with [base] */ open class MapperSerializationStrategy( private val base: SerializationStrategy, - private val serialize: (O) -> I + private val internalSerialize: (Encoder, O) -> I ) : SerializationStrategy { override val descriptor: SerialDescriptor = base.descriptor + constructor( + base: SerializationStrategy, + serialize: (O) -> I + ) : this(base, { _, o -> serialize(o) }) + override fun serialize(encoder: Encoder, value: O) { - base.serialize(encoder, serialize(value)) + base.serialize(encoder, internalSerialize(encoder, value)) } } diff --git a/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt b/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt index 2df9a1ba334..08d2ccee903 100644 --- a/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt +++ b/serialization/mapper/src/commonMain/kotlin/MapperSerializer.kt @@ -1,6 +1,8 @@ package dev.inmo.micro_utils.serialization.mapper +import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.KSerializer +import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder @@ -15,16 +17,28 @@ import kotlinx.serialization.encoding.Encoder */ open class MapperSerializer( private val base: KSerializer, - private val serialize: (O) -> I, - private val deserialize: (I) -> O -) : KSerializer { + private val serialize: (Encoder, O) -> I, + private val deserialize: (Decoder, I) -> O +) : KSerializer, + DeserializationStrategy by MapperDeserializationStrategy(base, deserialize), + SerializationStrategy by MapperSerializationStrategy(base, serialize) { override val descriptor: SerialDescriptor = base.descriptor - override fun deserialize(decoder: Decoder): O { - return deserialize(base.deserialize(decoder)) - } + constructor( + base: KSerializer, + serialize: (O) -> I, + deserialize: (I) -> O + ) : this(base, { _, o -> serialize(o) }, { _, i -> deserialize(i) }) - override fun serialize(encoder: Encoder, value: O) { - base.serialize(encoder, serialize(value)) - } + constructor( + base: KSerializer, + serialize: (Encoder, O) -> I, + deserialize: (I) -> O + ) : this(base, serialize, { _, i -> deserialize(i) }) + + constructor( + base: KSerializer, + serialize: (O) -> I, + deserialize: (Decoder, I) -> O + ) : this(base, { _, o -> serialize(o) }, deserialize) }