diff --git a/build.gradle b/build.gradle index ae66ee48..96797a98 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ buildscript { ext.kotlin_version = '1.3.0-rc-57' ext.serialization_version = '0.8.0-rc13' + ext.kotlinx_io_version = '0.1.0-alpha-15-rc13' repositories { jcenter() maven { @@ -34,7 +35,3 @@ allprojects { //maven { url 'https://jitpack.io' } } } - -subprojects { - apply plugin: 'kotlinx-serialization' -} diff --git a/dataforge-envelope/build.gradle b/dataforge-envelope/build.gradle new file mode 100644 index 00000000..fd1ea5e8 --- /dev/null +++ b/dataforge-envelope/build.gradle @@ -0,0 +1,13 @@ +plugins{ + id 'kotlin-platform-common' +} + +dependencies { + compile project(":dataforge-meta") + + compile "org.jetbrains.kotlinx:kotlinx-io:$kotlinx_io_version" + + compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" + testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common" + testCompile "org.jetbrains.kotlin:kotlin-test-common" +} \ No newline at end of file diff --git a/dataforge-envelope/src/main/kotlin/hep/dataforge/envelopes/Envelope.kt b/dataforge-envelope/src/main/kotlin/hep/dataforge/envelopes/Envelope.kt new file mode 100644 index 00000000..9368a452 --- /dev/null +++ b/dataforge-envelope/src/main/kotlin/hep/dataforge/envelopes/Envelope.kt @@ -0,0 +1,9 @@ +package hep.dataforge.envelopes + +import hep.dataforge.meta.Meta +import kotlinx.io.core.IoBuffer + +interface Envelope{ + val meta: Meta + val data: IoBuffer +} \ No newline at end of file diff --git a/dataforge-meta-common/build.gradle b/dataforge-meta/build.gradle similarity index 72% rename from dataforge-meta-common/build.gradle rename to dataforge-meta/build.gradle index a396466f..e13aef58 100644 --- a/dataforge-meta-common/build.gradle +++ b/dataforge-meta/build.gradle @@ -4,7 +4,7 @@ plugins{ dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" - compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" + testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common" testCompile "org.jetbrains.kotlin:kotlin-test-common" } \ No newline at end of file diff --git a/dataforge-meta/dataforge-meta-io/build.gradle b/dataforge-meta/dataforge-meta-io/build.gradle new file mode 100644 index 00000000..e56fdc44 --- /dev/null +++ b/dataforge-meta/dataforge-meta-io/build.gradle @@ -0,0 +1,19 @@ +plugins{ + id 'kotlin-platform-common' +} + +dependencies { + compile project(":dataforge-meta") + + + compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" + compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version" + compile "org.jetbrains.kotlinx:kotlinx-io:$kotlinx_io_version" + + testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common" + testCompile "org.jetbrains.kotlin:kotlin-test-common" +} + +allprojects { + apply plugin: 'kotlinx-serialization' +} \ No newline at end of file diff --git a/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/MetaFormat.kt b/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/MetaFormat.kt new file mode 100644 index 00000000..75cd9773 --- /dev/null +++ b/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/MetaFormat.kt @@ -0,0 +1,26 @@ +package hep.dataforge.meta.io + +import hep.dataforge.meta.Meta +import kotlinx.io.core.Input +import kotlinx.io.core.Output + +/** + * A format for meta serialization + */ +interface MetaFormat { + val name : String + val key : Short + + suspend fun write(meta: Meta, out: Output) + suspend fun read(input: Input): Meta +} + +/** + * Resolve format by its name. Null if not provided + */ +expect fun resolveFormat(name: String): MetaFormat? + +/** + * Resolve format by its binary key. Null if not provided + */ +expect fun resolveFormat(key: Short): MetaFormat? \ No newline at end of file diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Serializers.kt b/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/Serializers.kt similarity index 77% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Serializers.kt rename to dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/Serializers.kt index 1fd0a316..2297673e 100644 --- a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Serializers.kt +++ b/dataforge-meta/dataforge-meta-io/src/main/kotlin/hep/dataforge/meta/io/Serializers.kt @@ -1,46 +1,47 @@ -package hep.dataforge.meta +package hep.dataforge.meta.io -import kotlinx.serialization.json.* +import hep.dataforge.meta.* +import kotlinx.serialization.Serializable /*Universal serialization*/ -//sealed class MetaItemProxy { -// -// @Serializable -// class NumberValueProxy(val number: Number) : MetaItemProxy() -// -// @Serializable -// class StringValueProxy(val string: String) : MetaItemProxy() -// -// @Serializable -// class BooleanValueProxy(val boolean: Boolean) : MetaItemProxy() -// -// @Serializable -// object NullValueProxy : MetaItemProxy() -// -// @Serializable -// class MetaProxy(@Serializable val map: Map) : MetaItemProxy() -// -// @Serializable -// class MetaListProxy(@Serializable val nodes: List) : MetaItemProxy() -//} -// -// -//fun Meta.toMap(): Map { -// return this.items.mapValues { (_, value) -> -// when (value) { -// is MetaItem.ValueItem -> when (value.value.type) { -// ValueType.NUMBER -> MetaItemProxy.NumberValueProxy(value.value.number) -// ValueType.STRING -> MetaItemProxy.StringValueProxy(value.value.string) -// ValueType.BOOLEAN -> MetaItemProxy.BooleanValueProxy(value.value.boolean) -// ValueType.NULL -> MetaItemProxy.NullValueProxy -// } -// is MetaItem.SingleNodeItem -> MetaItemProxy.MetaProxy(value.node.toMap()) -// is MetaItem.MultiNodeItem -> MetaItemProxy.MetaListProxy(value.nodes.map { MetaItemProxy.MetaProxy(it.toMap()) }) -// } -// } -//} +sealed class MetaItemProxy { + + @Serializable + class NumberValueProxy(val number: Number) : MetaItemProxy() + + @Serializable + class StringValueProxy(val string: String) : MetaItemProxy() + + @Serializable + class BooleanValueProxy(val boolean: Boolean) : MetaItemProxy() + + @Serializable + object NullValueProxy : MetaItemProxy() + + @Serializable + class MetaProxy(@Serializable val map: Map) : MetaItemProxy() + + @Serializable + class MetaListProxy(@Serializable val nodes: List) : MetaItemProxy() +} + + +fun Meta.toMap(): Map { + return this.items.mapValues { (_, value) -> + when (value) { + is MetaItem.ValueItem<*> -> when (value.value.type) { + ValueType.NUMBER -> MetaItemProxy.NumberValueProxy(value.value.number) + ValueType.STRING -> MetaItemProxy.StringValueProxy(value.value.string) + ValueType.BOOLEAN -> MetaItemProxy.BooleanValueProxy(value.value.boolean) + ValueType.NULL -> MetaItemProxy.NullValueProxy + } + is MetaItem.SingleNodeItem<*> -> MetaItemProxy.MetaProxy(value.node.toMap()) + is MetaItem.MultiNodeItem<*> -> MetaItemProxy.MetaListProxy(value.nodes.map { MetaItemProxy.MetaProxy(it.toMap()) }) + } + } +} /*Direct JSON serialization*/ diff --git a/dataforge-meta-js/build.gradle b/dataforge-meta/dataforge-meta-js/build.gradle similarity index 55% rename from dataforge-meta-js/build.gradle rename to dataforge-meta/dataforge-meta-js/build.gradle index f884412d..af0d28ca 100644 --- a/dataforge-meta-js/build.gradle +++ b/dataforge-meta/dataforge-meta-js/build.gradle @@ -3,9 +3,8 @@ plugins{ } dependencies { - expectedBy project(":dataforge-meta-common") + expectedBy project(":dataforge-meta") compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" - compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version" testCompile "org.jetbrains.kotlin:kotlin-test-js" } diff --git a/dataforge-meta-jvm/build.gradle b/dataforge-meta/dataforge-meta-jvm/build.gradle similarity index 60% rename from dataforge-meta-jvm/build.gradle rename to dataforge-meta/dataforge-meta-jvm/build.gradle index f371911a..1f4379b0 100644 --- a/dataforge-meta-jvm/build.gradle +++ b/dataforge-meta/dataforge-meta-jvm/build.gradle @@ -3,11 +3,9 @@ plugins{ } dependencies { - expectedBy project(":dataforge-meta-common") + expectedBy project(":dataforge-meta") compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version" testCompile "org.jetbrains.kotlin:kotlin-test" testCompile "org.jetbrains.kotlin:kotlin-test-junit" } diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Config.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Config.kt similarity index 100% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Config.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/meta/Config.kt diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Delegates.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Delegates.kt similarity index 100% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Delegates.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/meta/Delegates.kt diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Meta.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Meta.kt similarity index 98% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Meta.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/meta/Meta.kt index b84a84e7..2d5eb1f1 100644 --- a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Meta.kt +++ b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Meta.kt @@ -96,11 +96,6 @@ abstract class MetaNode> : Meta { override fun hashCode(): Int { return items.hashCode() } - - override fun toString(): String { - return toJSON().toString() - } - } /** diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/MetaBuilder.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/MetaBuilder.kt similarity index 100% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/MetaBuilder.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/meta/MetaBuilder.kt diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/MutableMetaNode.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/MutableMetaNode.kt similarity index 100% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/MutableMetaNode.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/meta/MutableMetaNode.kt diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Specification.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Specification.kt similarity index 100% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Specification.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/meta/Specification.kt diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Styleable.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Styleable.kt similarity index 100% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Styleable.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/meta/Styleable.kt diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Value.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/meta/Value.kt similarity index 100% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/meta/Value.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/meta/Value.kt diff --git a/dataforge-meta-common/src/main/kotlin/hep/dataforge/names/Name.kt b/dataforge-meta/src/main/kotlin/hep/dataforge/names/Name.kt similarity index 100% rename from dataforge-meta-common/src/main/kotlin/hep/dataforge/names/Name.kt rename to dataforge-meta/src/main/kotlin/hep/dataforge/names/Name.kt diff --git a/dataforge-meta-common/src/test/kotlin/hep/dataforge/meta/MetaBuilderTest.kt b/dataforge-meta/src/test/kotlin/hep/dataforge/meta/MetaBuilderTest.kt similarity index 100% rename from dataforge-meta-common/src/test/kotlin/hep/dataforge/meta/MetaBuilderTest.kt rename to dataforge-meta/src/test/kotlin/hep/dataforge/meta/MetaBuilderTest.kt diff --git a/dataforge-meta-common/src/test/kotlin/hep/dataforge/meta/MetaDelegateTest.kt b/dataforge-meta/src/test/kotlin/hep/dataforge/meta/MetaDelegateTest.kt similarity index 100% rename from dataforge-meta-common/src/test/kotlin/hep/dataforge/meta/MetaDelegateTest.kt rename to dataforge-meta/src/test/kotlin/hep/dataforge/meta/MetaDelegateTest.kt diff --git a/dataforge-meta-common/src/test/kotlin/hep/dataforge/meta/SerializationTest.kt b/dataforge-meta/src/test/kotlin/hep/dataforge/meta/SerializationTest.kt similarity index 100% rename from dataforge-meta-common/src/test/kotlin/hep/dataforge/meta/SerializationTest.kt rename to dataforge-meta/src/test/kotlin/hep/dataforge/meta/SerializationTest.kt diff --git a/dataforge-meta-common/src/test/kotlin/hep/dataforge/names/NameTest.kt b/dataforge-meta/src/test/kotlin/hep/dataforge/names/NameTest.kt similarity index 100% rename from dataforge-meta-common/src/test/kotlin/hep/dataforge/names/NameTest.kt rename to dataforge-meta/src/test/kotlin/hep/dataforge/names/NameTest.kt diff --git a/settings.gradle b/settings.gradle index 655d929b..3cd11386 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,8 +14,12 @@ pluginManagement { } } -rootProject.name = 'dataforge-meta' +rootProject.name = 'dataforge-core' -include ":dataforge-meta-common" -include ":dataforge-meta-jvm" -include ":dataforge-meta-js" \ No newline at end of file +include ":dataforge-meta" +include ":dataforge-meta:dataforge-meta-jvm" +include ":dataforge-meta:dataforge-meta-js" + +include ":dataforge-meta:dataforge-meta-io" + +include ":dataforge-envelope" \ No newline at end of file