Add serialization modules and export kotlinx coroutines dep
This commit is contained in:
7 files changed
+95
-12
No files matched your search
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
@file:Suppress("UnstableApiUsage")
|
@file:Suppress("UnstableApiUsage")
|
||||||
|
|
||||||
include(":worker-core")
|
include(":worker-core")
|
||||||
include(":worker-serialization")
|
include(":worker-serialization-json")
|
||||||
|
include(":worker-serialization-protobuf")
|
||||||
include(":worker-gradle-plugin")
|
include(":worker-gradle-plugin")
|
||||||
|
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ kotlin {
|
|||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
jsMain.dependencies {
|
jsMain.dependencies {
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
|
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
|
||||||
}
|
}
|
||||||
|
|
||||||
commonTest.dependencies {
|
commonTest.dependencies {
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
kotlin("plugin.serialization")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
explicitApi()
|
||||||
|
|
||||||
|
js(IR) {
|
||||||
|
nodejs { binaries.executable() }
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
jsMain.dependencies {
|
||||||
|
api("org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.1")
|
||||||
|
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2026 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2026/1/17
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@file:OptIn(ExperimentalSerializationApi::class)
|
||||||
|
|
||||||
|
package cn.rtast.cfworker.serialization.json
|
||||||
|
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
|
public val json: Json = Json {
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
explicitNulls = false
|
||||||
|
classDiscriminator = "_json_type_"
|
||||||
|
encodeDefaults = true
|
||||||
|
coerceInputValues = true
|
||||||
|
decodeEnumsCaseInsensitive = true
|
||||||
|
isLenient = true
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline fun <reified T> T.toJson(): String {
|
||||||
|
return json.encodeToString(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline fun <reified T> String.fromJson(): T {
|
||||||
|
return json.decodeFromString<T>(this)
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
kotlin("plugin.serialization")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
explicitApi()
|
||||||
|
|
||||||
|
js(IR) {
|
||||||
|
nodejs { binaries.executable() }
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
jsMain.dependencies {
|
||||||
|
api("org.jetbrains.kotlinx:kotlinx-serialization-core:1.8.1")
|
||||||
|
api("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.8.1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2026 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2026/1/17
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@file:OptIn(ExperimentalSerializationApi::class)
|
||||||
|
|
||||||
|
package cn.rtast.cfworker.serialization.protobuf
|
||||||
|
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
|
import kotlinx.serialization.decodeFromByteArray
|
||||||
|
import kotlinx.serialization.encodeToByteArray
|
||||||
|
import kotlinx.serialization.protobuf.ProtoBuf
|
||||||
|
|
||||||
|
public inline fun <reified T> ByteArray.fromProtobuf(): T {
|
||||||
|
return ProtoBuf.decodeFromByteArray<T>(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline fun <reified T> T.toProtobuf(): ByteArray {
|
||||||
|
return ProtoBuf.encodeToByteArray(this)
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
plugins {
|
|
||||||
kotlin("multiplatform")
|
|
||||||
kotlin("plugin.serialization")
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
js(IR) {
|
|
||||||
nodejs { binaries.executable() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user