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

Commit 8c103be

Browse files
committed
feat: add response classes for BigDecimal and BigInteger types
1 parent c967150 commit 8c103be

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dev.slne.surf.cloud.api.common.netty.network.protocol.double
2+
3+
import dev.slne.surf.cloud.api.common.meta.SurfNettyPacket
4+
import dev.slne.surf.cloud.api.common.netty.network.protocol.CommonResponseType
5+
import dev.slne.surf.cloud.api.common.netty.network.protocol.CommonResponseTypeFactory
6+
import dev.slne.surf.cloud.api.common.netty.network.protocol.PacketFlow
7+
import dev.slne.surf.cloud.api.common.netty.packet.RespondingNettyPacket
8+
import dev.slne.surf.cloud.api.common.netty.packet.ResponseNettyPacket
9+
import dev.slne.surf.cloud.api.common.netty.packet.packetCodec
10+
import dev.slne.surf.cloud.api.common.netty.protocol.buffer.SurfByteBuf
11+
import java.math.BigDecimal
12+
13+
typealias BigDecimalResponsePacket = RespondingNettyPacket<BigDecimalResponse>
14+
15+
@SurfNettyPacket("big_decimal_response", PacketFlow.BIDIRECTIONAL)
16+
class BigDecimalResponse(override val value: BigDecimal) : ResponseNettyPacket(), CommonResponseType<BigDecimal> {
17+
companion object: CommonResponseTypeFactory<BigDecimalResponse, BigDecimal> {
18+
val STREAM_CODEC = packetCodec(BigDecimalResponse::write, ::BigDecimalResponse)
19+
20+
override fun create(value: BigDecimal): BigDecimalResponse {
21+
return BigDecimalResponse(value)
22+
}
23+
}
24+
25+
private constructor(buf: SurfByteBuf) : this(BigDecimal(buf.readUtf()))
26+
27+
private fun write(buf: SurfByteBuf) {
28+
buf.writeUtf(value.toString())
29+
}
30+
31+
operator fun component1() = value
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dev.slne.surf.cloud.api.common.netty.network.protocol.double
2+
3+
import dev.slne.surf.cloud.api.common.meta.SurfNettyPacket
4+
import dev.slne.surf.cloud.api.common.netty.network.protocol.CommonResponseType
5+
import dev.slne.surf.cloud.api.common.netty.network.protocol.CommonResponseTypeFactory
6+
import dev.slne.surf.cloud.api.common.netty.network.protocol.PacketFlow
7+
import dev.slne.surf.cloud.api.common.netty.packet.RespondingNettyPacket
8+
import dev.slne.surf.cloud.api.common.netty.packet.ResponseNettyPacket
9+
import dev.slne.surf.cloud.api.common.netty.packet.packetCodec
10+
import dev.slne.surf.cloud.api.common.netty.protocol.buffer.SurfByteBuf
11+
import java.math.BigDecimal
12+
13+
typealias OptionalBigDecimalResponsePacket = RespondingNettyPacket<OptionalBigDecimalResponse>
14+
15+
@SurfNettyPacket("optional_big_decimal_response", PacketFlow.BIDIRECTIONAL)
16+
class OptionalBigDecimalResponse(override val value: BigDecimal?) : ResponseNettyPacket(),
17+
CommonResponseType<BigDecimal?> {
18+
companion object : CommonResponseTypeFactory<OptionalBigDecimalResponse, BigDecimal?> {
19+
val STREAM_CODEC =
20+
packetCodec(OptionalBigDecimalResponse::write, ::OptionalBigDecimalResponse)
21+
22+
override fun create(value: BigDecimal?): OptionalBigDecimalResponse {
23+
return OptionalBigDecimalResponse(value)
24+
}
25+
}
26+
27+
private constructor(buf: SurfByteBuf) : this(buf.readNullableString()?.let { BigDecimal(it) })
28+
29+
private fun write(buf: SurfByteBuf) {
30+
buf.writeNullable(value?.toString())
31+
}
32+
33+
operator fun component1() = value
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package dev.slne.surf.cloud.api.common.netty.network.protocol.int
2+
3+
import dev.slne.surf.cloud.api.common.meta.SurfNettyPacket
4+
import dev.slne.surf.cloud.api.common.netty.network.protocol.CommonResponseType
5+
import dev.slne.surf.cloud.api.common.netty.network.protocol.CommonResponseTypeFactory
6+
import dev.slne.surf.cloud.api.common.netty.network.protocol.PacketFlow
7+
import dev.slne.surf.cloud.api.common.netty.packet.RespondingNettyPacket
8+
import dev.slne.surf.cloud.api.common.netty.packet.ResponseNettyPacket
9+
import dev.slne.surf.cloud.api.common.netty.packet.packetCodec
10+
import dev.slne.surf.cloud.api.common.netty.protocol.buffer.SurfByteBuf
11+
import java.math.BigInteger
12+
13+
typealias BigIntegerResponsePacket = RespondingNettyPacket<BigIntegerResponse>
14+
15+
@SurfNettyPacket("big_integer_response", PacketFlow.BIDIRECTIONAL)
16+
class BigIntegerResponse(override val value: BigInteger) : ResponseNettyPacket(),
17+
CommonResponseType<BigInteger> {
18+
companion object : CommonResponseTypeFactory<BigIntegerResponse, BigInteger> {
19+
val STREAM_CODEC = packetCodec(BigIntegerResponse::write, ::BigIntegerResponse)
20+
21+
override fun create(value: BigInteger): BigIntegerResponse {
22+
return BigIntegerResponse(value)
23+
}
24+
}
25+
26+
private constructor(buf: SurfByteBuf) : this(BigInteger(buf.readUtf()))
27+
28+
private fun write(buf: SurfByteBuf) {
29+
buf.writeUtf(value.toString())
30+
}
31+
32+
operator fun component1() = value
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dev.slne.surf.cloud.api.common.netty.network.protocol.int
2+
3+
import dev.slne.surf.cloud.api.common.meta.SurfNettyPacket
4+
import dev.slne.surf.cloud.api.common.netty.network.protocol.CommonResponseType
5+
import dev.slne.surf.cloud.api.common.netty.network.protocol.CommonResponseTypeFactory
6+
import dev.slne.surf.cloud.api.common.netty.network.protocol.PacketFlow
7+
import dev.slne.surf.cloud.api.common.netty.packet.RespondingNettyPacket
8+
import dev.slne.surf.cloud.api.common.netty.packet.ResponseNettyPacket
9+
import dev.slne.surf.cloud.api.common.netty.packet.packetCodec
10+
import dev.slne.surf.cloud.api.common.netty.protocol.buffer.SurfByteBuf
11+
import java.math.BigInteger
12+
13+
typealias OptionalBigIntegerResponsePacket = RespondingNettyPacket<OptionalBigIntegerResponse>
14+
15+
@SurfNettyPacket("optional_big_integer_response", PacketFlow.BIDIRECTIONAL)
16+
class OptionalBigIntegerResponse(override val value: BigInteger?) : ResponseNettyPacket(),
17+
CommonResponseType<BigInteger?> {
18+
companion object : CommonResponseTypeFactory<OptionalBigIntegerResponse, BigInteger?> {
19+
val STREAM_CODEC =
20+
packetCodec(OptionalBigIntegerResponse::write, ::OptionalBigIntegerResponse)
21+
22+
override fun create(value: BigInteger?): OptionalBigIntegerResponse {
23+
return OptionalBigIntegerResponse(value)
24+
}
25+
}
26+
27+
private constructor(buf: SurfByteBuf) : this(buf.readNullableString()?.let { BigInteger(it) })
28+
29+
private fun write(buf: SurfByteBuf) {
30+
buf.writeNullable(value?.toString())
31+
}
32+
33+
operator fun component1() = value
34+
}

0 commit comments

Comments
 (0)