Skip to content

Commit

Permalink
Use Json.encodeToBuffer from huanshankeji/kotlinx.serialization@0a4…
Browse files Browse the repository at this point in the history
…c57a

The "JSON serialization" performance result is on par with that of using `Json.encodeToSink`. Therefore, this change is not really necessary.
  • Loading branch information
ShreckYe committed Oct 31, 2024
1 parent d012ceb commit b4576d9
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 55 deletions.
1 change: 1 addition & 0 deletions frameworks/Kotlin/vertx-web-kotlinx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.m2
4 changes: 3 additions & 1 deletion frameworks/Kotlin/vertx-web-kotlinx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ plugins {
}

repositories {
mavenLocal() // TODO
mavenCentral()
}

val vertxVersion = "4.5.10"
val kotlinxSerializationVersion = "1.7.3"
val kotlinxSerializationVersion = "1.7.4-vertx-buffer-SNAPSHOT" // TODO
dependencies {
implementation(platform("io.vertx:vertx-stack-depchain:$vertxVersion"))
implementation("io.vertx:vertx-web")
Expand All @@ -30,6 +31,7 @@ dependencies {

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-io:$kotlinxSerializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json-vertx:$kotlinxSerializationVersion")
implementation("org.jetbrains.kotlinx:kotlinx-io-core:0.5.4")

implementation("org.jetbrains.kotlinx:kotlinx-html:0.11.0")
Expand Down
2 changes: 2 additions & 0 deletions frameworks/Kotlin/vertx-web-kotlinx/copy_maven_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mkdir -p .m2/repository/org/jetbrains/kotlinx/
cp -r ~/.m2/repository/org/jetbrains/kotlinx/kotlinx-serialization-* .m2/repository/org/jetbrains/kotlinx/
47 changes: 0 additions & 47 deletions frameworks/Kotlin/vertx-web-kotlinx/src/main/kotlin/KotlinxIo.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import io.vertx.sqlclient.Tuple
import kotlinx.coroutines.Dispatchers
import kotlinx.html.*
import kotlinx.html.stream.appendHTML
import kotlinx.io.buffered
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.io.encodeToSink
import kotlinx.serialization.json.vertx.encodeToBuffer
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

Expand Down Expand Up @@ -134,11 +133,9 @@ class MainVerticle(val hasDb: Boolean) : CoroutineVerticle(), CoroutineRouterSup
*/

// approach 3
end(Buffer.buffer().apply {
toRawSink().buffered().use { bufferedSink ->
@OptIn(ExperimentalSerializationApi::class)
Json.encodeToSink(serializer, requestHandler(it), bufferedSink)
}
end(Buffer.buffer().also { buffer ->
@OptIn(ExperimentalSerializationApi::class)
Json.encodeToBuffer(serializer, requestHandler(it), buffer)
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM gradle:8.10.2-jdk21

# Publish the dependencies to Maven local and run "copy_maven_local.sh" first.
COPY .m2/repository/org/jetbrains/kotlinx /root/.m2/repository/org/jetbrains/kotlinx
WORKDIR /vertx-web-kotlinx
COPY build.gradle.kts build.gradle.kts
COPY settings.gradle.kts settings.gradle.kts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM gradle:8.10.2-jdk21

# Publish the dependencies to Maven local and run "copy_maven_local.sh" first.
COPY .m2/repository/org/jetbrains/kotlinx /root/.m2/repository/org/jetbrains/kotlinx
WORKDIR /vertx-web-kotlinx
COPY build.gradle.kts build.gradle.kts
COPY settings.gradle.kts settings.gradle.kts
Expand Down

0 comments on commit b4576d9

Please sign in to comment.