mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
commit
8dd2e3f6f9
12
CHANGELOG.md
12
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`:
|
||||
|
@ -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
|
||||
|
@ -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" }
|
||||
|
||||
|
@ -16,11 +16,16 @@ import kotlinx.serialization.encoding.Encoder
|
||||
*/
|
||||
open class MapperDeserializationStrategy<I, O>(
|
||||
private val base: DeserializationStrategy<I>,
|
||||
private val deserialize: (I) -> O
|
||||
private val deserialize: (Decoder, I) -> O
|
||||
) : DeserializationStrategy<O> {
|
||||
override val descriptor: SerialDescriptor = base.descriptor
|
||||
|
||||
constructor(
|
||||
base: DeserializationStrategy<I>,
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -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<I, O>(
|
||||
private val base: SerializationStrategy<I>,
|
||||
private val serialize: (O) -> I
|
||||
private val internalSerialize: (Encoder, O) -> I
|
||||
) : SerializationStrategy<O> {
|
||||
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) {
|
||||
base.serialize(encoder, serialize(value))
|
||||
base.serialize(encoder, internalSerialize(encoder, value))
|
||||
}
|
||||
}
|
||||
|
@ -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<I, O>(
|
||||
private val base: KSerializer<I>,
|
||||
private val serialize: (O) -> I,
|
||||
private val deserialize: (I) -> O
|
||||
) : KSerializer<O> {
|
||||
private val serialize: (Encoder, O) -> I,
|
||||
private val deserialize: (Decoder, I) -> 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 fun deserialize(decoder: Decoder): O {
|
||||
return deserialize(base.deserialize(decoder))
|
||||
}
|
||||
constructor(
|
||||
base: KSerializer<I>,
|
||||
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<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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user