move to Kotlin 1.6.20 and KTor 2.0

This commit is contained in:
Alexander Nozik 2022-04-15 18:56:00 +03:00
parent 11143e4ba1
commit 3c6bc15716
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
11 changed files with 20 additions and 26 deletions

View File

@ -4,9 +4,11 @@
### Added ### Added
- Add `specOrNull` delegate to meta and Scheme - Add `specOrNull` delegate to meta and Scheme
- Suspended read methods to the `Binary` - Suspended read methods to the `Binary`
- Static `Meta` to all `DataSet`s
### Changed ### Changed
- `Factory` is now `fun interface` and uses `build` instead of `invoke`. `invoke moved to an extension. - `Factory` is now `fun interface` and uses `build` instead of `invoke`. `invoke moved to an extension.
- KTor 2.0
### Deprecated ### Deprecated

View File

@ -1,3 +1,5 @@
import ru.mipt.npm.gradle.KScienceVersions
plugins { plugins {
id("ru.mipt.npm.gradle.mpp") id("ru.mipt.npm.gradle.mpp")
id("ru.mipt.npm.gradle.native") id("ru.mipt.npm.gradle.native")
@ -18,7 +20,7 @@ kotlin {
commonMain { commonMain {
dependencies { dependencies {
api(project(":dataforge-context")) api(project(":dataforge-context"))
api(npmlibs.ktor.io) api("io.ktor:ktor-io:${KScienceVersions.ktorVersion}")
} }
} }
} }

View File

@ -62,7 +62,7 @@ internal class ByteArrayBinary(
public fun ByteArray.asBinary(): Binary = ByteArrayBinary(this) 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) { public fun Binary.toByteArray(): ByteArray = if (this is ByteArrayBinary) {
array.copyOf() // TODO do we need to ensure data safety here? array.copyOf() // TODO do we need to ensure data safety here?

View File

@ -34,7 +34,7 @@ public class EnvelopeBuilder : Envelope {
* Construct a data binary from given builder * Construct a data binary from given builder
*/ */
public inline fun data(block: Output.() -> Unit) { public inline fun data(block: Output.() -> Unit) {
data = buildByteArray { block() }.asBinary() data = ByteArray { block() }.asBinary()
} }
public fun seal(): Envelope = SimpleEnvelope(metaBuilder.seal(), data) public fun seal(): Envelope = SimpleEnvelope(metaBuilder.seal(), data)

View File

@ -54,9 +54,9 @@ public interface MetaFormatFactory : IOFormatFactory<Meta>, MetaFormat {
} }
} }
public fun Meta.toString(format: MetaFormat): String = buildByteArray { public fun Meta.toString(format: MetaFormat): String = ByteArray {
format.run { format.run {
writeObject(this@buildByteArray, this@toString) writeObject(this@ByteArray, this@toString)
} }
}.decodeToString() }.decodeToString()

View File

@ -26,7 +26,7 @@ public class TaggedEnvelopeFormat(
// ?: error("Meta format with key $metaFormatKey could not be resolved in $io") // ?: 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(START_SEQUENCE)
writeRawString(version.name) writeRawString(version.name)
writeShort(metaFormatKey) writeShort(metaFormatKey)

View File

@ -15,7 +15,6 @@ public fun Output.writeUtf8String(str: String) {
writeFully(str.encodeToByteArray()) writeFully(str.encodeToByteArray())
} }
@OptIn(ExperimentalIoApi::class)
public fun Input.readRawString(size: Int): String { public fun Input.readRawString(size: Int): String {
return Charsets.ISO_8859_1.newDecoder().decodeExactBytes(this, size) 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 fun Input.readSafeUtf8Line(): String = readUTF8Line() ?: error("Line not found")
public inline fun buildByteArray(expectedSize: Int = 16, block: Output.() -> Unit): ByteArray { public inline fun ByteArray(block: Output.() -> Unit): ByteArray =
val builder = BytePacketBuilder(expectedSize) buildPacket(block).readBytes()
builder.block()
return builder.build().readBytes()
}
public inline fun Binary(expectedSize: Int = 16, block: Output.() -> Unit): Binary = public inline fun Binary(block: Output.() -> Unit): Binary =
buildByteArray(expectedSize, block).asBinary() ByteArray(block).asBinary()
/** /**
* View section of a [Binary] as an independent binary * View section of a [Binary] as an independent binary

View File

@ -8,8 +8,8 @@ import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
fun Meta.toByteArray(format: MetaFormat = JsonMetaFormat) = buildByteArray { fun Meta.toByteArray(format: MetaFormat = JsonMetaFormat) = ByteArray {
format.writeObject(this@buildByteArray, this@toByteArray) format.writeObject(this@ByteArray, this@toByteArray)
} }
fun MetaFormat.fromByteArray(packet: ByteArray): Meta { fun MetaFormat.fromByteArray(packet: ByteArray): Meta {

View File

@ -4,7 +4,7 @@ import io.ktor.utils.io.core.ByteReadPacket
import io.ktor.utils.io.core.use import io.ktor.utils.io.core.use
fun <T : Any> IOFormat<T>.writeToByteArray(obj: T): ByteArray = buildByteArray { fun <T : Any> IOFormat<T>.writeToByteArray(obj: T): ByteArray = ByteArray {
writeObject(this, obj) writeObject(this, obj)
} }
fun <T : Any> IOFormat<T>.readFromByteArray(array: ByteArray): T = ByteReadPacket(array).use { fun <T : Any> IOFormat<T>.readFromByteArray(array: ByteArray): T = ByteReadPacket(array).use {

View File

@ -27,7 +27,7 @@ public object Builders {
dependenciesFromCurrentContext(wholeClasspath = true) dependenciesFromCurrentContext(wholeClasspath = true)
} }
hostConfiguration(defaultJvmScriptingHostConfiguration) hostConfiguration(defaultJvmScriptingHostConfiguration)
compilerOptions("-jvm-target", Runtime.version().feature().toString()) compilerOptions("-jvm-target", Runtime.version().feature().toString(),"-Xcontext-receivers")
} }
val evaluationConfiguration = ScriptEvaluationConfiguration { val evaluationConfiguration = ScriptEvaluationConfiguration {

View File

@ -1,13 +1,7 @@
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G
org.gradle.parallel=true org.gradle.parallel=true
kotlin.code.style=official kotlin.code.style=official
#kotlin.mpp.enableGranularSourceSetsMetadata=true
#kotlin.native.enableDependencyPropagation=false
kotlin.mpp.stability.nowarn=true kotlin.mpp.stability.nowarn=true
publishing.github=false toolsVersion=0.11.4-kotlin-1.6.20
publishing.sonatype=false
toolsVersion=0.11.1-kotlin-1.6.10