diff --git a/dataforge-io/src/commonTest/kotlin/hep/dataforge/io/MetaSerializerTest.kt b/dataforge-io/src/commonTest/kotlin/hep/dataforge/io/MetaSerializerTest.kt index 69b0427b..86a569a6 100644 --- a/dataforge-io/src/commonTest/kotlin/hep/dataforge/io/MetaSerializerTest.kt +++ b/dataforge-io/src/commonTest/kotlin/hep/dataforge/io/MetaSerializerTest.kt @@ -11,17 +11,17 @@ import kotlin.test.Test import kotlin.test.assertEquals class MetaSerializerTest { + val meta = Meta { + "a" put 22 + "node" put { + "b" put "DDD" + "c" put 11.1 + "array" put doubleArrayOf(1.0, 2.0, 3.0) + } + } + @Test fun testMetaSerialization() { - val meta = Meta { - "a" put 22 - "node" put { - "b" put "DDD" - "c" put 11.1 - "array" put doubleArrayOf(1.0, 2.0, 3.0) - } - } - val string = Json.indented.stringify(MetaSerializer, meta) val restored = Json.plain.parse(MetaSerializer, string) assertEquals(restored, meta) @@ -29,15 +29,6 @@ class MetaSerializerTest { @Test fun testCborSerialization() { - val meta = Meta { - "a" put 22 - "node" put { - "b" put "DDD" - "c" put 11.1 - "array" put doubleArrayOf(1.0, 2.0, 3.0) - } - } - val bytes = Cbor.dump(MetaSerializer, meta) println(bytes.contentToString()) val restored = Cbor.load(MetaSerializer, bytes) diff --git a/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/fileIO.kt b/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/fileIO.kt index 1fe9d59d..c9b4f1bf 100644 --- a/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/fileIO.kt +++ b/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/fileIO.kt @@ -1,9 +1,9 @@ package hep.dataforge.io -import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.DFExperimental import hep.dataforge.meta.EmptyMeta import hep.dataforge.meta.Meta +import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.isEmpty import kotlinx.io.* import java.nio.file.Files @@ -14,6 +14,7 @@ import kotlin.streams.asSequence /** * Resolve IOFormat based on type */ +@Suppress("UNCHECKED_CAST") @DFExperimental inline fun IOPlugin.resolveIOFormat(): IOFormat? { return ioFormats.values.find { it.type.isSuperclassOf(T::class) } as IOFormat? diff --git a/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/functionsJVM.kt b/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/functionsJVM.kt index fae986d7..ffb924ef 100644 --- a/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/functionsJVM.kt +++ b/dataforge-io/src/jvmMain/kotlin/hep/dataforge/io/functionsJVM.kt @@ -3,7 +3,6 @@ package hep.dataforge.io import hep.dataforge.io.functions.FunctionServer import hep.dataforge.io.functions.function import hep.dataforge.meta.Meta -import hep.dataforge.meta.buildMeta import hep.dataforge.names.Name import kotlin.reflect.KClass import kotlin.reflect.full.isSuperclassOf @@ -14,7 +13,7 @@ fun IOPlugin.resolveIOFormatName(type: KClass<*>): Name { ?: error("Can't resolve IOFormat for type $type") } -inline fun IOPlugin.generateFunctionMeta(functionName: String): Meta = buildMeta { +inline fun IOPlugin.generateFunctionMeta(functionName: String): Meta = Meta { FunctionServer.FUNCTION_NAME_KEY put functionName FunctionServer.INPUT_FORMAT_KEY put resolveIOFormatName(T::class).toString() FunctionServer.OUTPUT_FORMAT_KEY put resolveIOFormatName(R::class).toString() diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt index 833117b5..53a2e184 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Config.kt @@ -4,6 +4,7 @@ import hep.dataforge.names.Name import hep.dataforge.names.NameToken import hep.dataforge.names.asName import hep.dataforge.names.plus +import kotlinx.serialization.* //TODO add validator to configuration @@ -20,6 +21,7 @@ interface ObservableMeta : Meta { /** * Mutable meta representing object state */ +@Serializable class Config : AbstractMutableMeta(), ObservableMeta { private val listeners = HashSet() @@ -66,8 +68,19 @@ class Config : AbstractMutableMeta(), ObservableMeta { override fun empty(): Config = Config() - companion object { + @Serializer(Config::class) + companion object ConfigSerializer : KSerializer { + fun empty(): Config = Config() + override val descriptor: SerialDescriptor get() = MetaSerializer.descriptor + + override fun deserialize(decoder: Decoder): Config { + return MetaSerializer.deserialize(decoder).asConfig() + } + + override fun serialize(encoder: Encoder, value: Config) { + MetaSerializer.serialize(encoder, value) + } } } diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt index e5cda8f6..672a1922 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt @@ -15,6 +15,7 @@ import kotlinx.serialization.* */ @Serializable sealed class MetaItem { + @Serializable data class ValueItem(val value: Value) : MetaItem() { override fun toString(): String = value.toString() @@ -32,12 +33,13 @@ sealed class MetaItem { } @Serializable - data class NodeItem(val node: M) : MetaItem() { + data class NodeItem(@Serializable(MetaSerializer::class) val node: M) : MetaItem() { + //Fixing serializer for node could cause class cast problems, but it should not since Meta descendants are not serializeable override fun toString(): String = node.toString() @Serializer(NodeItem::class) - companion object : KSerializer> { - override val descriptor: SerialDescriptor get() = ValueSerializer.descriptor + companion object : KSerializer> { + override val descriptor: SerialDescriptor get() = MetaSerializer.descriptor override fun deserialize(decoder: Decoder): NodeItem<*> = NodeItem(MetaSerializer.deserialize(decoder)) @@ -199,8 +201,9 @@ abstract class AbstractMetaNode> : MetaNode, MetaBase() * * If the argument is possibly mutable node, it is copied on creation */ -class SealedMeta internal constructor(override val items: Map>) : - AbstractMetaNode() +class SealedMeta internal constructor( + override val items: Map> +) : AbstractMetaNode() /** * Generate sealed node from [this]. If it is already sealed return it as is diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MetaSerializer.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MetaSerializer.kt index 63a45664..6f0db59e 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MetaSerializer.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/MetaSerializer.kt @@ -8,8 +8,6 @@ import kotlinx.serialization.json.JsonObjectSerializer import kotlinx.serialization.json.JsonOutput -private class DeserializedMeta(override val items: Map>) : MetaBase() - /** * Serialized for meta */ @@ -26,7 +24,9 @@ object MetaSerializer : KSerializer { return if (decoder is JsonInput) { JsonObjectSerializer.deserialize(decoder).toMeta() } else { - DeserializedMeta(mapSerializer.deserialize(decoder)) + object : MetaBase() { + override val items: Map> = mapSerializer.deserialize(decoder) + } } } @@ -37,17 +37,4 @@ object MetaSerializer : KSerializer { mapSerializer.serialize(encoder, value.items) } } -} - -@Serializer(Config::class) -object ConfigSerializer : KSerializer { - override val descriptor: SerialDescriptor get() = MetaSerializer.descriptor - - override fun deserialize(decoder: Decoder): Config { - return MetaSerializer.deserialize(decoder).asConfig() - } - - override fun serialize(encoder: Encoder, value: Config) { - MetaSerializer.serialize(encoder, value) - } } \ No newline at end of file diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/scheme/ConfigurableDelegate.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/scheme/ConfigurableDelegate.kt index da02c30e..da6d92a8 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/scheme/ConfigurableDelegate.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/scheme/ConfigurableDelegate.kt @@ -168,8 +168,9 @@ fun Configurable.float(default: Float, key: Name? = null): ReadWriteProperty> Configurable.enum(default: E, key: Name? = null): ReadWriteProperty = - item(default, key).transform { it.enum() ?: default } +inline fun > Configurable.enum(default: E, key: Name? = null): ReadWriteProperty { + return item(default, key).transform { it.enum() ?: default } +} /* * Extra delegates for special cases diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index cc4fdc29..f3d88b1c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6ce793f2..a2bf1313 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew.bat b/gradlew.bat index 9618d8d9..62bd9b9c 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"