From cce914091c8f1812815b21bb01a39b3746901d78 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 21 Jan 2021 10:10:03 +0600 Subject: [PATCH 1/2] start 0.4.20 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4183e078748..ce81fa35ba1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.4.20 + ## 0.4.19 * `Coroutines`: diff --git a/gradle.properties b/gradle.properties index 728d265e171..cec7824686e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,5 +40,5 @@ dokka_version=1.4.20 # Project data group=dev.inmo -version=0.4.19 -android_code_version=23 +version=0.4.20 +android_code_version=24 From 14e666f18d86b845ea95f6fba7779fcbb18b3f07 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 21 Jan 2021 10:10:52 +0600 Subject: [PATCH 2/2] create encpsulator --- CHANGELOG.md | 4 ++++ serialization/encapsulator/build.gradle | 7 ++++++ .../encapsulator/Encapsulator.kt | 23 +++++++++++++++++++ .../encapsulator/src/main/AndroidManifest.xml | 1 + settings.gradle | 1 + 5 files changed, 36 insertions(+) create mode 100644 serialization/encapsulator/build.gradle create mode 100644 serialization/encapsulator/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/encapsulator/Encapsulator.kt create mode 100644 serialization/encapsulator/src/main/AndroidManifest.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index ce81fa35ba1..74476c33e82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.4.20 +* `Serialization` + * `Encapsulator`: + * Has been created + ## 0.4.19 * `Coroutines`: diff --git a/serialization/encapsulator/build.gradle b/serialization/encapsulator/build.gradle new file mode 100644 index 00000000000..7c54502f100 --- /dev/null +++ b/serialization/encapsulator/build.gradle @@ -0,0 +1,7 @@ +plugins { + id "org.jetbrains.kotlin.multiplatform" + id "org.jetbrains.kotlin.plugin.serialization" + id "com.android.library" +} + +apply from: "$mppProjectWithSerializationPresetPath" diff --git a/serialization/encapsulator/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/encapsulator/Encapsulator.kt b/serialization/encapsulator/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/encapsulator/Encapsulator.kt new file mode 100644 index 00000000000..bb9cdca393a --- /dev/null +++ b/serialization/encapsulator/src/commonMain/kotlin/dev/inmo/micro_utils/serialization/encapsulator/Encapsulator.kt @@ -0,0 +1,23 @@ +package dev.inmo.micro_utils.serialization.encapsulator + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.encoding.Encoder +import kotlin.reflect.KClass + +data class Encapsulator( + val klass: KClass, + val serializer: KSerializer +) { + fun encapsulate( + value: Any, + callback: KSerializer.(T) -> O + ): O? = if (klass.isInstance(value)) { + callback(serializer, value as T) + } else { + null + } +} + +fun Encapsulator.tryEncode(encoder: Encoder, value: Any) = encapsulate(value) { + encoder.encodeSerializableValue(this, it) +} diff --git a/serialization/encapsulator/src/main/AndroidManifest.xml b/serialization/encapsulator/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..eed58f5aa5d --- /dev/null +++ b/serialization/encapsulator/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index e53c506e681..6034af3c57d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,6 +22,7 @@ String[] includes = [ ":android:alerts:common", ":android:alerts:recyclerview", ":serialization:base64", + ":serialization:encapsulator", ":dokka" ]