From 8079c8a16bbae38f1358e8f35be0365174c01a65 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Sat, 4 Jan 2025 17:38:11 +0800 Subject: [PATCH] cleanup code and add jvmName annotation --- .space.kts | 3 --- api/build.gradle.kts | 1 - api/src/main/kotlin/cn/rtast/kwsify/Base64.kt | 27 ------------------- .../main/kotlin/cn/rtast/kwsify/IOperation.kt | 1 + api/src/main/kotlin/cn/rtast/kwsify/Kwsify.kt | 1 + .../main/kotlin/cn/rtast/kwsify/Subscriber.kt | 1 + src/main/kotlin/cn/rtast/kwsify/Const.kt | 16 ----------- src/main/kotlin/cn/rtast/kwsify/Main.kt | 4 +-- .../cn/rtast/kwsify/entity/ConnectionState.kt | 1 + .../cn/rtast/kwsify/entity/HeartbeatPacket.kt | 1 + .../cn/rtast/kwsify/entity/OPCodePacket.kt | 1 + .../entity/OutboundMessageBytesPacket.kt | 1 + .../cn/rtast/kwsify/entity/PublishPacket.kt | 1 + .../cn/rtast/kwsify/entity/SubscribePacket.kt | 1 + .../rtast/kwsify/entity/UnsubscribePacket.kt | 1 + .../kotlin/cn/rtast/kwsify/enums/OPCode.kt | 2 ++ .../kotlin/cn/rtast/kwsify/util/Binary.kt | 4 +-- src/main/kotlin/cn/rtast/kwsify/util/Json.kt | 25 ----------------- .../{WebsocketServer.kt => KWsifyServer.kt} | 3 ++- src/main/resources/conf.json | 6 ----- src/test/kotlin/test/TestServer.kt | 4 +-- src/test/resources/.gitkeep | 0 22 files changed, 20 insertions(+), 85 deletions(-) delete mode 100644 .space.kts delete mode 100644 api/src/main/kotlin/cn/rtast/kwsify/Base64.kt delete mode 100644 src/main/kotlin/cn/rtast/kwsify/Const.kt delete mode 100644 src/main/kotlin/cn/rtast/kwsify/util/Json.kt rename src/main/kotlin/cn/rtast/kwsify/util/{WebsocketServer.kt => KWsifyServer.kt} (98%) delete mode 100644 src/main/resources/conf.json delete mode 100644 src/test/resources/.gitkeep diff --git a/.space.kts b/.space.kts deleted file mode 100644 index bdbd54a..0000000 --- a/.space.kts +++ /dev/null @@ -1,3 +0,0 @@ -job("Build") { - gradlew("amazoncorretto:17-alpine", "build") -} diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 65429f2..37f0ec3 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -8,7 +8,6 @@ repositories { } dependencies { - api(libs.gson) api(libs.java.websocket) api(rootProject) } diff --git a/api/src/main/kotlin/cn/rtast/kwsify/Base64.kt b/api/src/main/kotlin/cn/rtast/kwsify/Base64.kt deleted file mode 100644 index aed7168..0000000 --- a/api/src/main/kotlin/cn/rtast/kwsify/Base64.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2025 RTAkland - * Author: RTAkland - * Date: 2025/1/3 - */ - -@file:Suppress("unused") - -package cn.rtast.kwsify - -import java.util.Base64 - -fun String.encodeToBase64(): String { - return Base64.getEncoder().encodeToString(this.toByteArray(Charsets.UTF_8)) -} - -fun ByteArray.encodeToBase64(): String { - return Base64.getEncoder().encodeToString(this) -} - -fun String.decodeToString(): String { - return String(Base64.getDecoder().decode(this), Charsets.UTF_8) -} - -fun String.decodeToByteArray(): ByteArray { - return Base64.getDecoder().decode(this) -} \ No newline at end of file diff --git a/api/src/main/kotlin/cn/rtast/kwsify/IOperation.kt b/api/src/main/kotlin/cn/rtast/kwsify/IOperation.kt index d315abc..07b046c 100644 --- a/api/src/main/kotlin/cn/rtast/kwsify/IOperation.kt +++ b/api/src/main/kotlin/cn/rtast/kwsify/IOperation.kt @@ -4,6 +4,7 @@ * Date: 2024/11/30 */ +@file:JvmName("IOperation") package cn.rtast.kwsify diff --git a/api/src/main/kotlin/cn/rtast/kwsify/Kwsify.kt b/api/src/main/kotlin/cn/rtast/kwsify/Kwsify.kt index 367bfcb..b9e0ab2 100644 --- a/api/src/main/kotlin/cn/rtast/kwsify/Kwsify.kt +++ b/api/src/main/kotlin/cn/rtast/kwsify/Kwsify.kt @@ -4,6 +4,7 @@ * Date: 2024/11/30 */ +@file:JvmName("Kwsify") package cn.rtast.kwsify diff --git a/api/src/main/kotlin/cn/rtast/kwsify/Subscriber.kt b/api/src/main/kotlin/cn/rtast/kwsify/Subscriber.kt index 3269cd9..5e7ea88 100644 --- a/api/src/main/kotlin/cn/rtast/kwsify/Subscriber.kt +++ b/api/src/main/kotlin/cn/rtast/kwsify/Subscriber.kt @@ -4,6 +4,7 @@ * Date: 2024/11/30 */ +@file:JvmName("Subscriber") package cn.rtast.kwsify diff --git a/src/main/kotlin/cn/rtast/kwsify/Const.kt b/src/main/kotlin/cn/rtast/kwsify/Const.kt deleted file mode 100644 index 844321d..0000000 --- a/src/main/kotlin/cn/rtast/kwsify/Const.kt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright © 2024 RTAkland - * Author: RTAkland - * Date: 2024/11/30 - */ - - -package cn.rtast.kwsify - -import com.google.gson.Gson -import com.google.gson.GsonBuilder - - -val gson: Gson = GsonBuilder() - .disableHtmlEscaping() - .create() diff --git a/src/main/kotlin/cn/rtast/kwsify/Main.kt b/src/main/kotlin/cn/rtast/kwsify/Main.kt index bce37c6..733fe33 100644 --- a/src/main/kotlin/cn/rtast/kwsify/Main.kt +++ b/src/main/kotlin/cn/rtast/kwsify/Main.kt @@ -7,7 +7,7 @@ package cn.rtast.kwsify -import cn.rtast.kwsify.util.WebsocketServer +import cn.rtast.kwsify.util.KWsifyServer import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.required @@ -16,5 +16,5 @@ fun main(args: Array) { val parser = ArgParser("kwsify-cli") val port by parser.option(ArgType.Int, shortName = "p", description = "Port number").required() parser.parse(args) - WebsocketServer(port).start() + KWsifyServer(port).start() } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/kwsify/entity/ConnectionState.kt b/src/main/kotlin/cn/rtast/kwsify/entity/ConnectionState.kt index 57f4c9c..f5b1daf 100644 --- a/src/main/kotlin/cn/rtast/kwsify/entity/ConnectionState.kt +++ b/src/main/kotlin/cn/rtast/kwsify/entity/ConnectionState.kt @@ -4,6 +4,7 @@ * Date: 2024/12/1 */ +@file:JvmName("ConnectionState") package cn.rtast.kwsify.entity diff --git a/src/main/kotlin/cn/rtast/kwsify/entity/HeartbeatPacket.kt b/src/main/kotlin/cn/rtast/kwsify/entity/HeartbeatPacket.kt index 4dfc71b..a64549f 100644 --- a/src/main/kotlin/cn/rtast/kwsify/entity/HeartbeatPacket.kt +++ b/src/main/kotlin/cn/rtast/kwsify/entity/HeartbeatPacket.kt @@ -4,6 +4,7 @@ * Date: 2025/1/4 */ +@file:JvmName("HeartbeatPacket") package cn.rtast.kwsify.entity diff --git a/src/main/kotlin/cn/rtast/kwsify/entity/OPCodePacket.kt b/src/main/kotlin/cn/rtast/kwsify/entity/OPCodePacket.kt index c35f84b..7ab8888 100644 --- a/src/main/kotlin/cn/rtast/kwsify/entity/OPCodePacket.kt +++ b/src/main/kotlin/cn/rtast/kwsify/entity/OPCodePacket.kt @@ -4,6 +4,7 @@ * Date: 2025/1/3 */ +@file:JvmName("OPCodePacket") package cn.rtast.kwsify.entity diff --git a/src/main/kotlin/cn/rtast/kwsify/entity/OutboundMessageBytesPacket.kt b/src/main/kotlin/cn/rtast/kwsify/entity/OutboundMessageBytesPacket.kt index 359d99e..d9fe5c8 100644 --- a/src/main/kotlin/cn/rtast/kwsify/entity/OutboundMessageBytesPacket.kt +++ b/src/main/kotlin/cn/rtast/kwsify/entity/OutboundMessageBytesPacket.kt @@ -4,6 +4,7 @@ * Date: 2025/1/3 */ +@file:JvmName("OutboundMessageBytesPacket") package cn.rtast.kwsify.entity diff --git a/src/main/kotlin/cn/rtast/kwsify/entity/PublishPacket.kt b/src/main/kotlin/cn/rtast/kwsify/entity/PublishPacket.kt index 7501442..929db74 100644 --- a/src/main/kotlin/cn/rtast/kwsify/entity/PublishPacket.kt +++ b/src/main/kotlin/cn/rtast/kwsify/entity/PublishPacket.kt @@ -4,6 +4,7 @@ * Date: 2024/12/1 */ +@file:JvmName("PublishPacket") package cn.rtast.kwsify.entity diff --git a/src/main/kotlin/cn/rtast/kwsify/entity/SubscribePacket.kt b/src/main/kotlin/cn/rtast/kwsify/entity/SubscribePacket.kt index 8c484bf..b201f8c 100644 --- a/src/main/kotlin/cn/rtast/kwsify/entity/SubscribePacket.kt +++ b/src/main/kotlin/cn/rtast/kwsify/entity/SubscribePacket.kt @@ -4,6 +4,7 @@ * Date: 2024/12/1 */ +@file:JvmName("SubscribePacket") package cn.rtast.kwsify.entity diff --git a/src/main/kotlin/cn/rtast/kwsify/entity/UnsubscribePacket.kt b/src/main/kotlin/cn/rtast/kwsify/entity/UnsubscribePacket.kt index 4d03a04..954a95a 100644 --- a/src/main/kotlin/cn/rtast/kwsify/entity/UnsubscribePacket.kt +++ b/src/main/kotlin/cn/rtast/kwsify/entity/UnsubscribePacket.kt @@ -4,6 +4,7 @@ * Date: 2024/12/1 */ +@file:JvmName("UnsubscribePacket") package cn.rtast.kwsify.entity diff --git a/src/main/kotlin/cn/rtast/kwsify/enums/OPCode.kt b/src/main/kotlin/cn/rtast/kwsify/enums/OPCode.kt index eadb31b..a7d53ff 100644 --- a/src/main/kotlin/cn/rtast/kwsify/enums/OPCode.kt +++ b/src/main/kotlin/cn/rtast/kwsify/enums/OPCode.kt @@ -4,6 +4,8 @@ * Date: 2024/11/30 */ +@file:JvmName("OPCode") + package cn.rtast.kwsify.enums object OPCode { diff --git a/src/main/kotlin/cn/rtast/kwsify/util/Binary.kt b/src/main/kotlin/cn/rtast/kwsify/util/Binary.kt index ab33ec5..bfeafbc 100644 --- a/src/main/kotlin/cn/rtast/kwsify/util/Binary.kt +++ b/src/main/kotlin/cn/rtast/kwsify/util/Binary.kt @@ -9,10 +9,10 @@ package cn.rtast.kwsify.util import java.nio.ByteBuffer -fun ByteBuffer.putBoolean(value: Boolean) { +internal fun ByteBuffer.putBoolean(value: Boolean) { put(if (value) 1.toByte() else 0.toByte()) } -fun ByteBuffer.getBoolean(): Boolean { +internal fun ByteBuffer.getBoolean(): Boolean { return get() == 1.toByte() } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/kwsify/util/Json.kt b/src/main/kotlin/cn/rtast/kwsify/util/Json.kt deleted file mode 100644 index 2c0f648..0000000 --- a/src/main/kotlin/cn/rtast/kwsify/util/Json.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright © 2024 RTAkland - * Author: RTAkland - * Date: 2024/11/30 - */ - -@file:Suppress("unused") - -package cn.rtast.kwsify.util - -import cn.rtast.kwsify.gson -import com.google.gson.reflect.TypeToken - -fun Any.toJson(): String { - return gson.toJson(this) -} - -inline fun String.fromJson(): T { - return gson.fromJson(this, T::class.java) -} - -inline fun String.fromArrayJson(): T { - return gson.fromJson(this, object : TypeToken() {}.type) -} - diff --git a/src/main/kotlin/cn/rtast/kwsify/util/WebsocketServer.kt b/src/main/kotlin/cn/rtast/kwsify/util/KWsifyServer.kt similarity index 98% rename from src/main/kotlin/cn/rtast/kwsify/util/WebsocketServer.kt rename to src/main/kotlin/cn/rtast/kwsify/util/KWsifyServer.kt index e78a417..de457cb 100644 --- a/src/main/kotlin/cn/rtast/kwsify/util/WebsocketServer.kt +++ b/src/main/kotlin/cn/rtast/kwsify/util/KWsifyServer.kt @@ -4,6 +4,7 @@ * Date: 2024/11/30 */ +@file:JvmName("KWsifyServer") package cn.rtast.kwsify.util @@ -16,7 +17,7 @@ import java.net.InetSocketAddress import java.nio.ByteBuffer import java.util.* -class WebsocketServer(private val port: Int) : WebSocketServer(InetSocketAddress(port)) { +class KWsifyServer(private val port: Int) : WebSocketServer(InetSocketAddress(port)) { private val connectionState = mutableListOf() diff --git a/src/main/resources/conf.json b/src/main/resources/conf.json deleted file mode 100644 index 43da1e0..0000000 --- a/src/main/resources/conf.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "host": "0.0.0.0", - "port": 5050, - "minClientIdLength": 10, - "randomClientId": true -} \ No newline at end of file diff --git a/src/test/kotlin/test/TestServer.kt b/src/test/kotlin/test/TestServer.kt index 03dfeac..9e0afad 100644 --- a/src/test/kotlin/test/TestServer.kt +++ b/src/test/kotlin/test/TestServer.kt @@ -7,8 +7,8 @@ package test -import cn.rtast.kwsify.util.WebsocketServer +import cn.rtast.kwsify.util.KWsifyServer fun main() { - WebsocketServer(8080).start() + KWsifyServer(8080).start() } \ No newline at end of file diff --git a/src/test/resources/.gitkeep b/src/test/resources/.gitkeep deleted file mode 100644 index e69de29..0000000