diff --git a/CHANGELOG.md b/CHANGELOG.md index 599556c1..67e4521f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,11 @@ ### Added - Add `specOrNull` delegate to meta and Scheme - Suspended read methods to the `Binary` +- Static `Meta` to all `DataSet`s ### Changed - `Factory` is now `fun interface` and uses `build` instead of `invoke`. `invoke moved to an extension. +- KTor 2.0 ### Deprecated diff --git a/dataforge-io/build.gradle.kts b/dataforge-io/build.gradle.kts index 4bc7f276..f4bdd54a 100644 --- a/dataforge-io/build.gradle.kts +++ b/dataforge-io/build.gradle.kts @@ -1,3 +1,5 @@ +import ru.mipt.npm.gradle.KScienceVersions + plugins { id("ru.mipt.npm.gradle.mpp") id("ru.mipt.npm.gradle.native") @@ -18,7 +20,7 @@ kotlin { commonMain { dependencies { api(project(":dataforge-context")) - api(npmlibs.ktor.io) + api("io.ktor:ktor-io:${KScienceVersions.ktorVersion}") } } } diff --git a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/Binary.kt b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/Binary.kt index 7473b783..e8b2ae16 100644 --- a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/Binary.kt +++ b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/Binary.kt @@ -62,7 +62,7 @@ internal class ByteArrayBinary( public fun ByteArray.asBinary(): Binary = ByteArrayBinary(this) /** - * Produce a [buildByteArray] representing an exact copy of this [Binary] + * Produce a [ByteArray] representing an exact copy of this [Binary] */ public fun Binary.toByteArray(): ByteArray = if (this is ByteArrayBinary) { array.copyOf() // TODO do we need to ensure data safety here? diff --git a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/EnvelopeBuilder.kt b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/EnvelopeBuilder.kt index a1afd15e..eedd2075 100644 --- a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/EnvelopeBuilder.kt +++ b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/EnvelopeBuilder.kt @@ -34,7 +34,7 @@ public class EnvelopeBuilder : Envelope { * Construct a data binary from given builder */ public inline fun data(block: Output.() -> Unit) { - data = buildByteArray { block() }.asBinary() + data = ByteArray { block() }.asBinary() } public fun seal(): Envelope = SimpleEnvelope(metaBuilder.seal(), data) diff --git a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/MetaFormat.kt b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/MetaFormat.kt index 37b42704..46d7b540 100644 --- a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/MetaFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/MetaFormat.kt @@ -54,9 +54,9 @@ public interface MetaFormatFactory : IOFormatFactory, MetaFormat { } } -public fun Meta.toString(format: MetaFormat): String = buildByteArray { +public fun Meta.toString(format: MetaFormat): String = ByteArray { format.run { - writeObject(this@buildByteArray, this@toString) + writeObject(this@ByteArray, this@toString) } }.decodeToString() diff --git a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/TaggedEnvelopeFormat.kt b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/TaggedEnvelopeFormat.kt index c4d281b4..96eaddb6 100644 --- a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/TaggedEnvelopeFormat.kt +++ b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/TaggedEnvelopeFormat.kt @@ -26,7 +26,7 @@ public class TaggedEnvelopeFormat( // ?: error("Meta format with key $metaFormatKey could not be resolved in $io") - private fun Tag.toBinary() = Binary(24) { + private fun Tag.toBinary() = Binary { writeRawString(START_SEQUENCE) writeRawString(version.name) writeShort(metaFormatKey) @@ -149,7 +149,7 @@ public class TaggedEnvelopeFormat( override fun peekFormat(io: IOPlugin, binary: Binary): EnvelopeFormat? { return try { - binary.read{ + binary.read { val header = readRawString(6) return@read when (header.substring(2..5)) { VERSION.DF02.name -> TaggedEnvelopeFormat(io, VERSION.DF02) diff --git a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/ioMisc.kt b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/ioMisc.kt index 5895380e..acb16916 100644 --- a/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/ioMisc.kt +++ b/dataforge-io/src/commonMain/kotlin/space/kscience/dataforge/io/ioMisc.kt @@ -15,7 +15,6 @@ public fun Output.writeUtf8String(str: String) { writeFully(str.encodeToByteArray()) } -@OptIn(ExperimentalIoApi::class) public fun Input.readRawString(size: Int): String { return Charsets.ISO_8859_1.newDecoder().decodeExactBytes(this, size) } @@ -24,14 +23,11 @@ public fun Input.readUtf8String(): String = readBytes().decodeToString() public fun Input.readSafeUtf8Line(): String = readUTF8Line() ?: error("Line not found") -public inline fun buildByteArray(expectedSize: Int = 16, block: Output.() -> Unit): ByteArray { - val builder = BytePacketBuilder(expectedSize) - builder.block() - return builder.build().readBytes() -} +public inline fun ByteArray(block: Output.() -> Unit): ByteArray = + buildPacket(block).readBytes() -public inline fun Binary(expectedSize: Int = 16, block: Output.() -> Unit): Binary = - buildByteArray(expectedSize, block).asBinary() +public inline fun Binary(block: Output.() -> Unit): Binary = + ByteArray(block).asBinary() /** * View section of a [Binary] as an independent binary diff --git a/dataforge-io/src/commonTest/kotlin/space/kscience/dataforge/io/MetaFormatTest.kt b/dataforge-io/src/commonTest/kotlin/space/kscience/dataforge/io/MetaFormatTest.kt index d142e746..f231801f 100644 --- a/dataforge-io/src/commonTest/kotlin/space/kscience/dataforge/io/MetaFormatTest.kt +++ b/dataforge-io/src/commonTest/kotlin/space/kscience/dataforge/io/MetaFormatTest.kt @@ -8,8 +8,8 @@ import kotlin.test.Test import kotlin.test.assertEquals -fun Meta.toByteArray(format: MetaFormat = JsonMetaFormat) = buildByteArray { - format.writeObject(this@buildByteArray, this@toByteArray) +fun Meta.toByteArray(format: MetaFormat = JsonMetaFormat) = ByteArray { + format.writeObject(this@ByteArray, this@toByteArray) } fun MetaFormat.fromByteArray(packet: ByteArray): Meta { diff --git a/dataforge-io/src/commonTest/kotlin/space/kscience/dataforge/io/ioTestUtils.kt b/dataforge-io/src/commonTest/kotlin/space/kscience/dataforge/io/ioTestUtils.kt index e99dcbd5..8eeb526b 100644 --- a/dataforge-io/src/commonTest/kotlin/space/kscience/dataforge/io/ioTestUtils.kt +++ b/dataforge-io/src/commonTest/kotlin/space/kscience/dataforge/io/ioTestUtils.kt @@ -4,7 +4,7 @@ import io.ktor.utils.io.core.ByteReadPacket import io.ktor.utils.io.core.use -fun IOFormat.writeToByteArray(obj: T): ByteArray = buildByteArray { +fun IOFormat.writeToByteArray(obj: T): ByteArray = ByteArray { writeObject(this, obj) } fun IOFormat.readFromByteArray(array: ByteArray): T = ByteReadPacket(array).use { diff --git a/dataforge-scripting/src/jvmMain/kotlin/space/kscience/dataforge/scripting/Builders.kt b/dataforge-scripting/src/jvmMain/kotlin/space/kscience/dataforge/scripting/Builders.kt index 19c6e640..89750159 100644 --- a/dataforge-scripting/src/jvmMain/kotlin/space/kscience/dataforge/scripting/Builders.kt +++ b/dataforge-scripting/src/jvmMain/kotlin/space/kscience/dataforge/scripting/Builders.kt @@ -27,7 +27,7 @@ public object Builders { dependenciesFromCurrentContext(wholeClasspath = true) } hostConfiguration(defaultJvmScriptingHostConfiguration) - compilerOptions("-jvm-target", Runtime.version().feature().toString()) + compilerOptions("-jvm-target", Runtime.version().feature().toString(),"-Xcontext-receivers") } val evaluationConfiguration = ScriptEvaluationConfiguration { diff --git a/gradle.properties b/gradle.properties index 9b925f8e..0de6ab36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,7 @@ -org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G org.gradle.parallel=true kotlin.code.style=official -#kotlin.mpp.enableGranularSourceSetsMetadata=true -#kotlin.native.enableDependencyPropagation=false kotlin.mpp.stability.nowarn=true -publishing.github=false -publishing.sonatype=false - -toolsVersion=0.11.1-kotlin-1.6.10 +toolsVersion=0.11.4-kotlin-1.6.20