Convert sharable ChannelHandlers to objects where possible

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
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 import io.netty.handler.codec.MessageToByteEncoder
@ChannelHandler.Sharable @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) { override fun encode(ctx: ChannelHandlerContext, msg: Js5Request, out: ByteBuf) {
when (msg) { when (msg) {
is Js5Request.Group -> { is Js5Request.Group -> {

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

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

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

Loading…
Cancel
Save