From a5bcddae6e9c0be229e79fc74c57e1c2c1a72193 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 13 Feb 2020 16:32:30 +0600 Subject: [PATCH] add loadModule --- CHANGELOG.md | 1 + .../kotlin/com/insanusmokrassar/sdi/HelperTools.kt | 7 +++++++ .../kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt | 11 +++++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt create mode 100644 src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a4ef01..f9b7aad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.1.2 * All reflection support methods are internal +* Added `lodModule` functions for more useful working with modules loading ## 0.1.1 diff --git a/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt b/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt new file mode 100644 index 0000000..dc40876 --- /dev/null +++ b/src/commonMain/kotlin/com/insanusmokrassar/sdi/HelperTools.kt @@ -0,0 +1,7 @@ +package com.insanusmokrassar.sdi + +import kotlinx.serialization.ImplicitReflectionSerializer +import kotlinx.serialization.json.Json + +@ImplicitReflectionSerializer +fun loadModule(json: String): Module = Json.nonstrict.parse(Module.serializer(), json) diff --git a/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt new file mode 100644 index 0000000..b5c4804 --- /dev/null +++ b/src/jvmMain/kotlin/com/insanusmokrassar/sdi/JVMHelperTools.kt @@ -0,0 +1,11 @@ +package com.insanusmokrassar.sdi + +import kotlinx.io.InputStream +import kotlinx.serialization.ImplicitReflectionSerializer +import java.io.File + +@ImplicitReflectionSerializer +fun loadModule(stream: InputStream) = loadModule(stream.reader().readText()) + +@ImplicitReflectionSerializer +fun loadModule(file: File) = loadModule(file.inputStream())