From bd6cdb553032f9c7b8f0e2742c7e3e93c6887696 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 13 Dec 2020 18:37:16 +0000 Subject: [PATCH] Convert sharable ChannelHandlers to objects where possible Signed-off-by: Graham --- .../main/kotlin/org/openrs2/protocol/js5/Js5RequestEncoder.kt | 2 +- .../kotlin/org/openrs2/protocol/js5/Js5ResponseEncoder.kt | 2 +- .../kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt | 2 +- .../kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5RequestEncoder.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5RequestEncoder.kt index 71f85e71f0..27a6acfd00 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5RequestEncoder.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5RequestEncoder.kt @@ -6,7 +6,7 @@ import io.netty.channel.ChannelHandlerContext import io.netty.handler.codec.MessageToByteEncoder @ChannelHandler.Sharable -public class Js5RequestEncoder : MessageToByteEncoder(Js5Request::class.java) { +public object Js5RequestEncoder : MessageToByteEncoder(Js5Request::class.java) { override fun encode(ctx: ChannelHandlerContext, msg: Js5Request, out: ByteBuf) { when (msg) { is Js5Request.Group -> { diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoder.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoder.kt index ccd6882e0c..94c55dab4f 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoder.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoder.kt @@ -8,7 +8,7 @@ import io.netty.handler.codec.MessageToByteEncoder import kotlin.math.min @ChannelHandler.Sharable -public class Js5ResponseEncoder : MessageToByteEncoder(Js5Response::class.java) { +public object Js5ResponseEncoder : MessageToByteEncoder(Js5Response::class.java) { override fun encode(ctx: ChannelHandlerContext, msg: Js5Response, out: ByteBuf) { out.writeByte(msg.archive) out.writeShort(msg.group) diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt index 881731c28b..5be0968250 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5RequestEncoderTest.kt @@ -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().use { actual -> diff --git a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt index 64add6d3a5..45671736d8 100644 --- a/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt +++ b/protocol/src/test/kotlin/org/openrs2/protocol/js5/Js5ResponseEncoderTest.kt @@ -33,7 +33,7 @@ object Js5ResponseEncoderTest { @Test fun testEncodeEmpty() { - val channel = EmbeddedChannel(Js5ResponseEncoder()) + val channel = EmbeddedChannel(Js5ResponseEncoder) assertThrows { 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()))