Merge pull request #229 from InsanusMokrassar/0.17.4

0.17.4
This commit is contained in:
InsanusMokrassar 2023-03-09 23:23:55 +06:00 committed by GitHub
commit cea65fc76e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 200 additions and 3 deletions

View File

@ -1,5 +1,13 @@
# Changelog
## 0.17.4
* `Serialization`:
* `Mapper`:
* Module inited
* `Versions`:
* `Compose`: `1.3.1-rc02` -> `1.3.1`
## 0.17.3
* `Common`:

View File

@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.17.3
android_code_version=185
version=0.17.4
android_code_version=186

View File

@ -6,7 +6,7 @@ kt-coroutines = "1.6.4"
kslog = "1.0.0"
jb-compose = "1.3.1-rc01"
jb-compose = "1.3.1"
jb-exposed = "0.41.1"
jb-dokka = "1.7.20"

View File

@ -0,0 +1,7 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
}
apply from: "$mppProjectWithSerializationPresetPath"

View File

@ -0,0 +1,99 @@
package dev.inmo.micro_utils.serialization.mapper
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.serializer
import kotlin.reflect.KClass
/**
* Will create [MapperSerializationStrategy] to allow you to map [O] to [I] using [serialize] lambda during
* serialization process
*/
inline fun <reified I : Any, O> SerializationStrategy<I>.mapSerialization(
noinline serialize: (O) -> I
) = MapperSerializationStrategy(
this,
serialize
)
/**
* Will create [MapperDeserializationStrategy] to allow you to map [I] to [O] using [deserialize] lambda during
* deserialization process
*/
inline fun <reified I : Any, O> DeserializationStrategy<I>.mapDeserialization(
noinline deserialize: (I) -> O
) = MapperDeserializationStrategy(
this,
deserialize
)
/**
* Will create [MapperSerializer] to allow you to map [O] to [I] and vice verse using [serialize]/[deserialize] lambda during
* serialization/deserialization process
*/
inline fun <reified I : Any, O> KSerializer<I>.mapFullSerialization(
noinline serialize: (O) -> I,
noinline deserialize: (I) -> O
) = MapperSerializer(
this,
serialize,
deserialize
)
/**
* Will create [MapperSerializationStrategy] to allow you to map [O] to [I] using [serialize] lambda during
* serialization process
*/
@OptIn(InternalSerializationApi::class)
inline fun <reified I : Any, O> KClass<I>.mapSerialization(
serializer: SerializationStrategy<I> = serializer(),
noinline serialize: (O) -> I
) = serializer.mapSerialization(serialize)
/**
* Will create [MapperDeserializationStrategy] to allow you to map [I] to [O] using [deserialize] lambda during
* deserialization process
*/
@OptIn(InternalSerializationApi::class)
inline fun <reified I : Any, O> KClass<I>.mapDeserialization(
serializer: DeserializationStrategy<I> = serializer(),
noinline deserialize: (I) -> O
) = serializer.mapDeserialization(deserialize)
/**
* Will create [MapperSerializer] to allow you to map [O] to [I] and vice verse using [serialize]/[deserialize] lambda during
* serialization/deserialization process
*/
@OptIn(InternalSerializationApi::class)
inline fun <reified I : Any, O> KClass<I>.mapFullSerialization(
serializer: KSerializer<I> = serializer(),
noinline serialize: (O) -> I,
noinline deserialize: (I) -> O
) = serializer.mapFullSerialization(serialize, deserialize)
/**
* Will create [MapperSerializationStrategy] to allow you to map [O] to [I] using [serialize] lambda during
* serialization process
*/
inline fun <reified I : Any, O> mappedSerializationStrategy(
noinline serialize: (O) -> I,
) = serializer<I>().mapSerialization(serialize)
/**
* Will create [MapperDeserializationStrategy] to allow you to map [I] to [O] using [deserialize] lambda during
* deserialization process
*/
inline fun <reified I : Any, O> mappedDeserializationStrategy(
noinline deserialize: (I) -> O
) = serializer<I>().mapDeserialization(deserialize)
/**
* Will create [MapperSerializer] to allow you to map [O] to [I] and vice verse using [serialize]/[deserialize] lambda during
* serialization/deserialization process
*/
inline fun <reified I : Any, O> mappedSerializer(
noinline serialize: (O) -> I,
noinline deserialize: (I) -> O
) = serializer<I>().mapFullSerialization(serialize, deserialize)

View File

@ -0,0 +1,26 @@
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
/**
* Use this serializer when you have deserializable type [I] and want to map it to some [O] in process of
* deserialization
*
* @param base Serializer for [I]
* @param deserialize Will be used in [deserialize] method to convert deserialized by [base] [I] to [O]
*/
open class MapperDeserializationStrategy<I, O>(
private val base: DeserializationStrategy<I>,
private val deserialize: (I) -> O
) : DeserializationStrategy<O> {
override val descriptor: SerialDescriptor = base.descriptor
override fun deserialize(decoder: Decoder): O {
return deserialize(base.deserialize(decoder))
}
}

View File

@ -0,0 +1,25 @@
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
/**
* Use this serializer when you have serializable type [I] and want to map it to some [O] in process of
* serialization
*
* @param base Serializer for [I]
* @param serialize Will be used in [serialize] 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
) : SerializationStrategy<O> {
override val descriptor: SerialDescriptor = base.descriptor
override fun serialize(encoder: Encoder, value: O) {
base.serialize(encoder, serialize(value))
}
}

View File

@ -0,0 +1,30 @@
package dev.inmo.micro_utils.serialization.mapper
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
/**
* Use this serializer when you have serializable type [I] and want to map it to some [O] in process of
* serialization/deserialization
*
* @param base Serializer for [I]
* @param serialize Will be used in [serialize] method to convert incoming [O] to [I] and serialize with [base]
* @param deserialize Will be used in [deserialize] method to convert deserialized by [base] [I] to [O]
*/
open class MapperSerializer<I, O>(
private val base: KSerializer<I>,
private val serialize: (O) -> I,
private val deserialize: (I) -> O
) : KSerializer<O> {
override val descriptor: SerialDescriptor = base.descriptor
override fun deserialize(decoder: Decoder): O {
return deserialize(base.deserialize(decoder))
}
override fun serialize(encoder: Encoder, value: O) {
base.serialize(encoder, serialize(value))
}
}

View File

@ -0,0 +1 @@
<manifest package="dev.inmo.micro_utils.serialization.mapper"/>

View File

@ -37,6 +37,7 @@ String[] includes = [
":serialization:base64",
":serialization:encapsulator",
":serialization:typed_serializer",
":serialization:mapper",
":startup:plugin",
":startup:launcher",