Convert sharable ChannelHandlers to objects where possible

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 1c13fec91f
commit bd6cdb5530
  1. 2
      protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5RequestEncoder.kt
  2. 2
      protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoder.kt
  3. 2
      protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt
  4. 4
      protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt

@ -6,7 +6,7 @@ import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.MessageToByteEncoder
@ChannelHandler.Sharable
public class Js5RequestEncoder : MessageToByteEncoder<Js5Request>(Js5Request::class.java) {
public object Js5RequestEncoder : MessageToByteEncoder<Js5Request>(Js5Request::class.java) {
override fun encode(ctx: ChannelHandlerContext, msg: Js5Request, out: ByteBuf) {
when (msg) {
is Js5Request.Group -> {

@ -8,7 +8,7 @@ import io.netty.handler.codec.MessageToByteEncoder
import kotlin.math.min
@ChannelHandler.Sharable
public class Js5ResponseEncoder : MessageToByteEncoder<Js5Response>(Js5Response::class.java) {
public object Js5ResponseEncoder : MessageToByteEncoder<Js5Response>(Js5Response::class.java) {
override fun encode(ctx: ChannelHandlerContext, msg: Js5Response, out: ByteBuf) {
out.writeByte(msg.archive)
out.writeShort(msg.group)

@ -20,7 +20,7 @@ object Js5RequestEncoderTest {
}
private fun testEncode(request: Js5Request, expected: ByteArray) {
val channel = EmbeddedChannel(Js5RequestEncoder())
val channel = EmbeddedChannel(Js5RequestEncoder)
channel.writeOutbound(request)
channel.readOutbound<ByteBuf>().use { actual ->

@ -33,7 +33,7 @@ object Js5ResponseEncoderTest {
@Test
fun testEncodeEmpty() {
val channel = EmbeddedChannel(Js5ResponseEncoder())
val channel = EmbeddedChannel(Js5ResponseEncoder)
assertThrows<EncoderException> {
channel.writeOutbound(Js5Response(true, 2, 3, Unpooled.EMPTY_BUFFER))
@ -41,7 +41,7 @@ object Js5ResponseEncoderTest {
}
private fun testEncode(container: String, encoded: String, prefetch: Boolean) {
val channel = EmbeddedChannel(Js5ResponseEncoder())
val channel = EmbeddedChannel(Js5ResponseEncoder)
read(container).use { buf ->
channel.writeOutbound(Js5Response(prefetch, 2, 3, buf.retain()))

Loading…
Cancel
Save