Merge pull request #366 from InsanusMokrassar/0.20.24

0.20.24
This commit is contained in:
InsanusMokrassar 2024-01-04 10:26:00 +06:00 committed by GitHub
commit 8dd2e3f6f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 22 deletions

View File

@ -1,5 +1,17 @@
# Changelog # 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 ## 0.20.23
* `Versions`: * `Versions`:

View File

@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.20.23 version=0.20.24
android_code_version=229 android_code_version=230

View File

@ -10,7 +10,7 @@ jb-compose = "1.5.11"
jb-exposed = "0.45.0" jb-exposed = "0.45.0"
jb-dokka = "1.9.10" jb-dokka = "1.9.10"
korlibs = "4.0.10" korlibs = "5.3.0"
uuid = "0.8.2" uuid = "0.8.2"
ktor = "2.3.7" ktor = "2.3.7"
@ -21,7 +21,7 @@ koin = "3.5.3"
okio = "3.7.0" okio = "3.7.0"
ksp = "1.9.22-1.0.16" ksp = "1.9.21-1.0.16"
kotlin-poet = "1.15.3" kotlin-poet = "1.15.3"
versions = "0.50.0" 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" } kslog = { module = "dev.inmo:kslog", version.ref = "kslog" }
klock = { module = "com.soywiz.korlibs.klock:klock", version.ref = "korlibs" } klock = { module = "com.soywiz.korge:korlibs-time", version.ref = "korlibs" }
krypto = { module = "com.soywiz.korlibs.krypto:krypto", version.ref = "korlibs" } krypto = { module = "com.soywiz.korge:korlibs-crypto", version.ref = "korlibs" }
uuid = { module = "com.benasher44:uuid", version.ref = "uuid" } uuid = { module = "com.benasher44:uuid", version.ref = "uuid" }
koin = { module = "io.insert-koin:koin-core", version.ref = "koin" } koin = { module = "io.insert-koin:koin-core", version.ref = "koin" }

View File

@ -16,11 +16,16 @@ import kotlinx.serialization.encoding.Encoder
*/ */
open class MapperDeserializationStrategy<I, O>( open class MapperDeserializationStrategy<I, O>(
private val base: DeserializationStrategy<I>, private val base: DeserializationStrategy<I>,
private val deserialize: (I) -> O private val deserialize: (Decoder, I) -> O
) : DeserializationStrategy<O> { ) : DeserializationStrategy<O> {
override val descriptor: SerialDescriptor = base.descriptor override val descriptor: SerialDescriptor = base.descriptor
constructor(
base: DeserializationStrategy<I>,
deserialize: (I) -> O
) : this(base, { _, i -> deserialize(i) })
override fun deserialize(decoder: Decoder): O { override fun deserialize(decoder: Decoder): O {
return deserialize(base.deserialize(decoder)) return deserialize(decoder, base.deserialize(decoder))
} }
} }

View File

@ -1,9 +1,7 @@
package dev.inmo.micro_utils.serialization.mapper package dev.inmo.micro_utils.serialization.mapper
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
/** /**
@ -11,15 +9,20 @@ import kotlinx.serialization.encoding.Encoder
* serialization * serialization
* *
* @param base Serializer for [I] * @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<I, O>( open class MapperSerializationStrategy<I, O>(
private val base: SerializationStrategy<I>, private val base: SerializationStrategy<I>,
private val serialize: (O) -> I private val internalSerialize: (Encoder, O) -> I
) : SerializationStrategy<O> { ) : SerializationStrategy<O> {
override val descriptor: SerialDescriptor = base.descriptor override val descriptor: SerialDescriptor = base.descriptor
constructor(
base: SerializationStrategy<I>,
serialize: (O) -> I
) : this(base, { _, o -> serialize(o) })
override fun serialize(encoder: Encoder, value: O) { override fun serialize(encoder: Encoder, value: O) {
base.serialize(encoder, serialize(value)) base.serialize(encoder, internalSerialize(encoder, value))
} }
} }

View File

@ -1,6 +1,8 @@
package dev.inmo.micro_utils.serialization.mapper package dev.inmo.micro_utils.serialization.mapper
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.Encoder
@ -15,16 +17,28 @@ import kotlinx.serialization.encoding.Encoder
*/ */
open class MapperSerializer<I, O>( open class MapperSerializer<I, O>(
private val base: KSerializer<I>, private val base: KSerializer<I>,
private val serialize: (O) -> I, private val serialize: (Encoder, O) -> I,
private val deserialize: (I) -> O private val deserialize: (Decoder, I) -> O
) : KSerializer<O> { ) : KSerializer<O>,
DeserializationStrategy<O> by MapperDeserializationStrategy<I, O>(base, deserialize),
SerializationStrategy<O> by MapperSerializationStrategy<I, O>(base, serialize) {
override val descriptor: SerialDescriptor = base.descriptor override val descriptor: SerialDescriptor = base.descriptor
override fun deserialize(decoder: Decoder): O { constructor(
return deserialize(base.deserialize(decoder)) base: KSerializer<I>,
} serialize: (O) -> I,
deserialize: (I) -> O
) : this(base, { _, o -> serialize(o) }, { _, i -> deserialize(i) })
override fun serialize(encoder: Encoder, value: O) { constructor(
base.serialize(encoder, serialize(value)) base: KSerializer<I>,
} serialize: (Encoder, O) -> I,
deserialize: (I) -> O
) : this(base, serialize, { _, i -> deserialize(i) })
constructor(
base: KSerializer<I>,
serialize: (O) -> I,
deserialize: (Decoder, I) -> O
) : this(base, { _, o -> serialize(o) }, deserialize)
} }