Moved to mpp structure
This commit is contained in:
parent
ad059dea33
commit
c1d004ec3e
@ -24,14 +24,14 @@ buildscript {
|
||||
|
||||
description = "The basic interfaces for DataForge meta-data"
|
||||
|
||||
group 'hep.dataforge'
|
||||
version '0.1.1-SNAPSHOT'
|
||||
group = 'hep.dataforge'
|
||||
version = '0.1.1-SNAPSHOT'
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url = "http://dl.bintray.com/kotlin/kotlin-eap" }
|
||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||
maven { url = "https://kotlin.bintray.com/kotlinx" }
|
||||
//maven { url 'https://jitpack.io' }
|
||||
}
|
||||
}
|
||||
|
65
dataforge-meta-io/build.gradle
Normal file
65
dataforge-meta-io/build.gradle
Normal file
@ -0,0 +1,65 @@
|
||||
plugins {
|
||||
id 'kotlin-multiplatform'// version '1.3.0-rc-57'
|
||||
id 'kotlinx-serialization'
|
||||
}
|
||||
repositories {
|
||||
maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' }
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
fromPreset(presets.js, 'js')
|
||||
// For ARM, preset should be changed to presets.iosArm32 or presets.iosArm64
|
||||
// For Linux, preset should be changed to e.g. presets.linuxX64
|
||||
// For MacOS, preset should be changed to e.g. presets.macosX64
|
||||
//fromPreset(presets.iosX64, 'ios')
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation project(":dataforge-meta")
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-common"
|
||||
implementation 'org.jetbrains.kotlin:kotlin-reflect'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-io:$kotlinx_io_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test-common'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-io-jvm:$kotlinx_io_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
|
||||
}
|
||||
}
|
||||
jsMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
|
||||
}
|
||||
}
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test-js'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
|
||||
}
|
||||
}
|
||||
// iosMain {
|
||||
// }
|
||||
// iosTest {
|
||||
// }
|
||||
}
|
||||
}
|
@ -15,12 +15,12 @@ interface MetaFormat {
|
||||
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?
|
||||
///**
|
||||
// * 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?
|
@ -0,0 +1,51 @@
|
||||
package hep.dataforge.meta.io
|
||||
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.MetaItem
|
||||
import hep.dataforge.meta.ValueType
|
||||
import hep.dataforge.meta.boolean
|
||||
import kotlinx.serialization.Polymorphic
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/*Universal serialization*/
|
||||
|
||||
@Serializable
|
||||
class MetaProxy(val map: Map<String, @Polymorphic MetaItemProxy>)
|
||||
|
||||
|
||||
@Serializable
|
||||
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 SingleMetaProxy(val node: MetaProxy) : MetaItemProxy()
|
||||
|
||||
@Serializable
|
||||
class MetaListProxy(val list: List<@Polymorphic MetaProxy>) : MetaItemProxy()
|
||||
}
|
||||
|
||||
|
||||
fun Meta.toMap(): MetaProxy {
|
||||
return MetaProxy(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.SingleMetaProxy(value.node.toMap())
|
||||
is MetaItem.MultiNodeItem<*> -> MetaItemProxy.MetaListProxy(value.nodes.map { it.toMap() })
|
||||
}
|
||||
})
|
||||
}
|
@ -1,47 +1,7 @@
|
||||
package hep.dataforge.meta.io
|
||||
|
||||
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<String, MetaItemProxy>) : MetaItemProxy()
|
||||
|
||||
@Serializable
|
||||
class MetaListProxy(@Serializable val nodes: List<MetaProxy>) : MetaItemProxy()
|
||||
}
|
||||
|
||||
|
||||
fun Meta.toMap(): Map<String, MetaItemProxy> {
|
||||
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()) })
|
||||
}
|
||||
}
|
||||
}
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
|
||||
/*Direct JSON serialization*/
|
@ -0,0 +1,47 @@
|
||||
package io
|
||||
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.meta.io.MetaItemProxy
|
||||
import hep.dataforge.meta.io.toMap
|
||||
import kotlinx.serialization.json.JSON
|
||||
import kotlinx.serialization.serializer
|
||||
import kotlin.test.Test
|
||||
|
||||
class MetaItemProxyTest {
|
||||
@Test
|
||||
fun testGeneration() {
|
||||
MetaItemProxy::class.serializer()
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testProxySerialization() {
|
||||
val meta = buildMeta {
|
||||
"a" to 2
|
||||
"b" to {
|
||||
"c" to "ddd"
|
||||
"d" to 2.2
|
||||
}
|
||||
}
|
||||
val json = JSON.indented.stringify(meta.toMap())
|
||||
println(json)
|
||||
// val result: Map<String, MetaItemProxy> = JSON.parse(json)
|
||||
// assertEquals(meta,result.to)
|
||||
}
|
||||
|
||||
// @Test
|
||||
// fun testJSONSerialization() {
|
||||
// val meta = buildMeta {
|
||||
// "a" to 2
|
||||
// "b" to {
|
||||
// "c" to "ddd"
|
||||
// "d" to 2.2
|
||||
// }
|
||||
// }
|
||||
// val json = meta.toJSON()
|
||||
// println(json)
|
||||
// val result = json.toMeta()
|
||||
// assertEquals(meta, result)
|
||||
// }
|
||||
|
||||
}
|
@ -1,10 +1,63 @@
|
||||
plugins{
|
||||
id 'kotlin-platform-common'
|
||||
plugins {
|
||||
id 'kotlin-multiplatform'// version '1.3.0-rc-57'
|
||||
id 'kotlinx-serialization'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
|
||||
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test-common"
|
||||
repositories {
|
||||
maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' }
|
||||
mavenCentral()
|
||||
}
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.jvm, 'jvm')
|
||||
fromPreset(presets.js, 'js')
|
||||
// For ARM, preset should be changed to presets.iosArm32 or presets.iosArm64
|
||||
// For Linux, preset should be changed to e.g. presets.linuxX64
|
||||
// For MacOS, preset should be changed to e.g. presets.macosX64
|
||||
//fromPreset(presets.iosX64, 'ios')
|
||||
}
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-common"
|
||||
implementation 'org.jetbrains.kotlin:kotlin-reflect'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-io:$kotlinx_io_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test-common'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
|
||||
}
|
||||
}
|
||||
jsMain {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
|
||||
}
|
||||
}
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlin:kotlin-test-js'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
|
||||
}
|
||||
}
|
||||
// iosMain {
|
||||
// }
|
||||
// iosTest {
|
||||
// }
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
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'
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
plugins{
|
||||
id 'kotlin-platform-js'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
expectedBy project(":dataforge-meta")
|
||||
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test-js"
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
plugins{
|
||||
id 'kotlin-platform-jvm'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
expectedBy project(":dataforge-meta")
|
||||
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test-junit"
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
sourceCompatibility = "1.8"
|
@ -1,52 +0,0 @@
|
||||
package hep.dataforge.meta
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SerializationTest {
|
||||
|
||||
@Test
|
||||
fun testJSONSerialization() {
|
||||
val meta = buildMeta {
|
||||
"a" to 2
|
||||
"b" to {
|
||||
"c" to "ddd"
|
||||
"d" to 2.2
|
||||
}
|
||||
}
|
||||
val json = meta.toJSON()
|
||||
println(json)
|
||||
val result = json.toMeta()
|
||||
assertEquals(meta, result)
|
||||
}
|
||||
|
||||
// @Test
|
||||
// fun testIndirectSerialization() {
|
||||
// val meta = buildMeta {
|
||||
// "a" to 2
|
||||
// "b" to {
|
||||
// "c" to "ddd"
|
||||
// "d" to 2.2
|
||||
// }
|
||||
// }
|
||||
// val json = JSON.stringify(meta.toMap())
|
||||
// println(json)
|
||||
//// val result = json.toMeta()
|
||||
//// assertEquals(meta, result)
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// fun testWeirdSerialization() {
|
||||
// val meta = buildMeta {
|
||||
// "a" to 2
|
||||
// "b" to {
|
||||
// "c" to "ddd"
|
||||
// "d" to 2.2
|
||||
// }
|
||||
// }
|
||||
// val json = JSON.stringify(meta.toJSON())
|
||||
// println(json)
|
||||
// val result: JsonObject = JSON.parse(json)
|
||||
// assertEquals(meta, result.toMeta())
|
||||
// }
|
||||
}
|
@ -10,16 +10,23 @@ pluginManagement {
|
||||
if (requested.id.id == "kotlin-platform-js") {
|
||||
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
|
||||
}
|
||||
if (requested.id.id == "kotlin-multiplatform") {
|
||||
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url = 'http://dl.bintray.com/kotlin/kotlin-eap' }
|
||||
mavenCentral()
|
||||
maven { url = 'https://plugins.gradle.org/m2/' }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rootProject.name = 'dataforge-core'
|
||||
|
||||
include ":dataforge-meta"
|
||||
include ":dataforge-meta:dataforge-meta-jvm"
|
||||
include ":dataforge-meta:dataforge-meta-js"
|
||||
|
||||
include ":dataforge-meta:dataforge-meta-io"
|
||||
include ":dataforge-meta-io"
|
||||
|
||||
include ":dataforge-envelope"
|
Loading…
Reference in New Issue
Block a user