Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 4454c0e

Browse files
committed
feat: enhance BigDecimal serialization support and update dependencies
- Implemented `BigDecimalSerializer` using `CloudBufSerializer`. - Added `writeBigDecimal` and `readBigDecimal` methods to `SurfByteBuf`. - Updated `CloudCoreInstance` initializers to include `NettyListenerRegistryProcessor`. - Bumped `netty` to `4.2.3.Final` and `kotlin-byte-buf-serializer` to `1.1.0`.
1 parent 58c9f7b commit 4454c0e

File tree

4 files changed

+55
-37
lines changed

4 files changed

+55
-37
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
velocity-version = "3.4.0-SNAPSHOT"
33
aide-reflection = "1.3"
4-
netty = "4.2.2.Final"
4+
netty = "4.2.3.Final"
55
netty-tcnative = "2.0.72.Final"
66
datafixerupper = "8.0.16"
77
#byte-buddy = "1.15.10"
@@ -17,7 +17,7 @@ zstd-jni = "1.5.7-4"
1717
luckperms-api = "5.4"
1818
reactive-streams = "1.0.4"
1919
ehcache = "3.10.8"
20-
kotlin-byte-buf-serializer = "1.0.0"
20+
kotlin-byte-buf-serializer = "1.1.0"
2121
voicechat-api = "2.5.27"
2222
discord-webhooks = "1.0"
2323
konf = "1.1.2"
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
package dev.slne.surf.cloud.api.common.netty.network.codec.kotlinx.java
22

3-
import kotlinx.serialization.KSerializer
3+
import dev.slne.surf.cloud.api.common.netty.network.codec.kotlinx.CloudBufSerializer
4+
import dev.slne.surf.cloud.api.common.netty.protocol.buffer.SurfByteBuf
45
import kotlinx.serialization.Serializable
5-
import kotlinx.serialization.descriptors.PrimitiveKind
6-
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
7-
import kotlinx.serialization.encoding.Decoder
8-
import kotlinx.serialization.encoding.Encoder
6+
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
7+
import kotlinx.serialization.descriptors.element
98
import java.math.BigDecimal
109

1110
typealias SerializableBigDecimal = @Serializable(with = BigDecimalSerializer::class) BigDecimal
1211

13-
object BigDecimalSerializer : KSerializer<BigDecimal> {
14-
override val descriptor = PrimitiveSerialDescriptor("BigDecimal", PrimitiveKind.STRING)
12+
object BigDecimalSerializer : CloudBufSerializer<BigDecimal>() {
13+
override val descriptor = buildClassSerialDescriptor("dev.slne.surf.cloud.BigDecimal") {
14+
element<ByteArray>("unscaledValue")
15+
element<Int>("scale")
16+
element<Int>("precision")
17+
}
1518

16-
override fun serialize(
17-
encoder: Encoder,
18-
value: BigDecimal
19-
) {
20-
encoder.encodeString(value.toString())
19+
override fun serialize0(buf: SurfByteBuf, value: BigDecimal) {
20+
buf.writeBigDecimal(value)
2121
}
2222

23-
override fun deserialize(decoder: Decoder): BigDecimal {
24-
return BigDecimal(decoder.decodeString())
23+
override fun deserialize0(buf: SurfByteBuf): BigDecimal {
24+
return buf.readBigDecimal()
2525
}
2626
}

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/netty/protocol/buffer/SurfByteBuf.kt

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import net.kyori.adventure.nbt.CompoundBinaryTag
3232
import net.kyori.adventure.sound.Sound
3333
import net.kyori.adventure.text.Component
3434
import java.io.*
35+
import java.math.BigDecimal
36+
import java.math.BigInteger
37+
import java.math.MathContext
3538
import java.net.Inet4Address
3639
import java.net.InetSocketAddress
3740
import java.net.URI
@@ -97,11 +100,11 @@ open class SurfByteBuf(source: ByteBuf) : WrappedByteBuf(source) {
97100

98101
private val GSON = Gson()
99102

100-
fun <B: ByteBuf, T> streamCodecFromKotlin(serializer: KSerializer<T>): StreamCodec<B, T> {
103+
fun <B : ByteBuf, T> streamCodecFromKotlin(serializer: KSerializer<T>): StreamCodec<B, T> {
101104
return SerializerCodec(serializer)
102105
}
103106

104-
private class SerializerCodec<B: ByteBuf, T>(private val serializer: KSerializer<T>) :
107+
private class SerializerCodec<B : ByteBuf, T>(private val serializer: KSerializer<T>) :
105108
StreamCodec<B, T> {
106109
override fun decode(buf: B): T {
107110
return SurfCloudBufSerializer.serializer.decodeFromBuf(buf, serializer)
@@ -696,6 +699,27 @@ open class SurfByteBuf(source: ByteBuf) : WrappedByteBuf(source) {
696699
fun <B : ByteBuf> readDuration(buf: B): Duration {
697700
return buf.readLong().milliseconds
698701
}
702+
703+
fun <B : ByteBuf> writeBigInteger(buf: B, value: BigInteger) {
704+
writeByteArray(buf, value.toByteArray())
705+
}
706+
707+
fun <B : ByteBuf> readBigInteger(buf: B): BigInteger {
708+
return BigInteger(readByteArray(buf))
709+
}
710+
711+
fun <B : ByteBuf> writeBigDecimal(buf: B, value: BigDecimal) {
712+
writeBigInteger(buf, value.unscaledValue())
713+
buf.writeVarInt(value.scale())
714+
buf.writeVarInt(value.precision())
715+
}
716+
717+
fun <B : ByteBuf> readBigDecimal(buf: B): BigDecimal {
718+
val unscaledValue = readBigInteger(buf)
719+
val scale = buf.readVarInt()
720+
val precision = buf.readVarInt()
721+
return BigDecimal(unscaledValue, scale, MathContext(precision))
722+
}
699723
}
700724

701725

@@ -873,6 +897,10 @@ open class SurfByteBuf(source: ByteBuf) : WrappedByteBuf(source) {
873897
fun readSingleton(classLoader: ClassLoader) = readSingleton(this, classLoader)
874898
fun writeDuration(duration: Duration) = writeDuration(this, duration)
875899
fun readDuration() = readDuration(this)
900+
fun writeBigInteger(value: BigInteger) = writeBigInteger(this, value)
901+
fun readBigInteger() = readBigInteger(this)
902+
fun writeBigDecimal(value: BigDecimal) = writeBigDecimal(this, value)
903+
fun readBigDecimal() = readBigDecimal(this)
876904
// @formatter:on
877905
// endregion
878906

@@ -1094,7 +1122,8 @@ fun <B : ByteBuf> B.writeInetSocketAddress(address: InetSocketAddress) =
10941122
SurfByteBuf.writeInetSocketAddress(this, address)
10951123

10961124
fun <B : ByteBuf> B.readCompoundTag() = SurfByteBuf.readCompoundTag(this)
1097-
fun <B : ByteBuf> B.writeCompoundTag(tag: CompoundBinaryTag) = SurfByteBuf.writeCompoundTag(this, tag)
1125+
fun <B : ByteBuf> B.writeCompoundTag(tag: CompoundBinaryTag) =
1126+
SurfByteBuf.writeCompoundTag(this, tag)
10981127

10991128
fun <B : ByteBuf> B.readZonedDateTime() = SurfByteBuf.readZonedDateTime(this)
11001129
fun <B : ByteBuf> B.writeZonedDateTime(time: ZonedDateTime) =
@@ -1112,6 +1141,11 @@ fun <B : ByteBuf> B.writeSingleton(singleton: Any) = SurfByteBuf.writeSingleton(
11121141
fun <B : ByteBuf> B.writeDuration(duration: Duration) = SurfByteBuf.writeDuration(this, duration)
11131142
fun <B : ByteBuf> B.readDuration() = SurfByteBuf.readDuration(this)
11141143

1144+
fun <B : ByteBuf> B.writeBigInteger(value: BigInteger) = SurfByteBuf.writeBigInteger(this, value)
1145+
fun <B : ByteBuf> B.readBigInteger() = SurfByteBuf.readBigInteger(this)
1146+
fun <B : ByteBuf> B.writeBigDecimal(value: BigDecimal) = SurfByteBuf.writeBigDecimal(this, value)
1147+
fun <B : ByteBuf> B.readBigDecimal() = SurfByteBuf.readBigDecimal(this)
1148+
11151149
fun ByteBuf.wrap() = SurfByteBuf(this)
11161150
// endregion
11171151

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/CloudCoreInstance.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import dev.slne.surf.cloud.api.common.util.classloader.JoinClassLoader
1010
import dev.slne.surf.cloud.api.common.util.forEachOrdered
1111
import dev.slne.surf.cloud.core.common.event.CloudEventListenerBeanPostProcessor
1212
import dev.slne.surf.cloud.core.common.netty.network.EncryptionManager
13+
import dev.slne.surf.cloud.core.common.netty.registry.listener.processor.NettyListenerRegistryProcessor
1314
import dev.slne.surf.cloud.core.common.player.punishment.CloudPlayerPunishmentManagerBridgeImpl
1415
import dev.slne.surf.cloud.core.common.player.task.PrePlayerJoinTaskAutoRegistrationHandler
1516
import dev.slne.surf.cloud.core.common.plugin.task.CloudBeforeStartTaskHandler
@@ -173,24 +174,6 @@ class CloudCoreInstance : CloudInstance {
173174
setProperty("logging.include-application-name", "false")
174175
setProperty("logging.level.root", "info")
175176

176-
setProperty("spring.jpa.show-sql", "false")
177-
setProperty(
178-
"spring.jpa.properties.jakarta.persistence.sharedCache.mode",
179-
"ENABLE_SELECTIVE"
180-
)
181-
setProperty("spring.jpa.properties.hibernate.generate_statistics", "true")
182-
setProperty("spring.jpa.properties.hibernate.cache.use_second_level_cache", "true")
183-
setProperty("spring.jpa.properties.hibernate.cache.use_query_cache", "true")
184-
setProperty("spring.jpa.properties.hibernate.cache.region.factory_class", "jcache")
185-
setProperty(
186-
"spring.jpa.properties.hibernate.javax.cache.provider",
187-
"org.ehcache.jsr107.EhcacheCachingProvider"
188-
)
189-
setProperty(
190-
"spring.jpa.properties.hibernate.javax.cache.missing_cache_strategy",
191-
"create"
192-
)
193-
194177
setProperty(
195178
"spring.autoconfigure.exclude",
196179
childConfigurations.values.flatMap { it.excludedAutoConfiguration }
@@ -229,6 +212,7 @@ class CloudCoreInstance : CloudInstance {
229212
)
230213
})
231214
.initializers(NettyPacketProcessor())
215+
.sources(NettyListenerRegistryProcessor::class.java)
232216

233217

234218
// builder.parent(parentContext)

0 commit comments

Comments
 (0)