forked from openrs2/openrs2
parent
30b605d719
commit
96ea95394c
@ -0,0 +1,3 @@ |
|||||||
|
package org.openrs2.protocol.jaggrab |
||||||
|
|
||||||
|
public data class JaggrabRequest(public val path: String) |
@ -0,0 +1,19 @@ |
|||||||
|
package org.openrs2.protocol.jaggrab |
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandler |
||||||
|
import io.netty.channel.ChannelHandlerContext |
||||||
|
import io.netty.handler.codec.DecoderException |
||||||
|
import io.netty.handler.codec.MessageToMessageDecoder |
||||||
|
|
||||||
|
@ChannelHandler.Sharable |
||||||
|
public object JaggrabRequestDecoder : MessageToMessageDecoder<String>() { |
||||||
|
private const val PREFIX = "JAGGRAB " |
||||||
|
|
||||||
|
override fun decode(ctx: ChannelHandlerContext, msg: String, out: MutableList<Any>) { |
||||||
|
if (!msg.startsWith(PREFIX)) { |
||||||
|
throw DecoderException("JAGGRAB request has invalid prefix") |
||||||
|
} |
||||||
|
|
||||||
|
out += JaggrabRequest(msg.substring(PREFIX.length)) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
package org.openrs2.protocol.jaggrab |
||||||
|
|
||||||
|
import io.netty.channel.ChannelHandler |
||||||
|
import io.netty.channel.ChannelHandlerContext |
||||||
|
import io.netty.handler.codec.MessageToMessageEncoder |
||||||
|
|
||||||
|
@ChannelHandler.Sharable |
||||||
|
public object JaggrabRequestEncoder : MessageToMessageEncoder<JaggrabRequest>() { |
||||||
|
override fun encode(ctx: ChannelHandlerContext, msg: JaggrabRequest, out: MutableList<Any>) { |
||||||
|
out += "JAGGRAB ${msg.path}\n\n" |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
package org.openrs2.protocol.jaggrab |
||||||
|
|
||||||
|
import io.netty.channel.embedded.EmbeddedChannel |
||||||
|
import io.netty.handler.codec.DecoderException |
||||||
|
import org.junit.jupiter.api.assertThrows |
||||||
|
import kotlin.test.Test |
||||||
|
import kotlin.test.assertEquals |
||||||
|
|
||||||
|
object JaggrabRequestDecoderTest { |
||||||
|
@Test |
||||||
|
fun testDecode() { |
||||||
|
val channel = EmbeddedChannel(JaggrabRequestDecoder) |
||||||
|
channel.writeInbound("JAGGRAB /runescape.pack200") |
||||||
|
|
||||||
|
val actual = channel.readInbound<JaggrabRequest>() |
||||||
|
assertEquals(JaggrabRequest("/runescape.pack200"), actual) |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
fun testInvalid() { |
||||||
|
val channel = EmbeddedChannel(JaggrabRequestDecoder) |
||||||
|
|
||||||
|
assertThrows<DecoderException> { |
||||||
|
channel.writeInbound("Hello, world!") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
package org.openrs2.protocol.jaggrab |
||||||
|
|
||||||
|
import io.netty.channel.embedded.EmbeddedChannel |
||||||
|
import kotlin.test.Test |
||||||
|
import kotlin.test.assertEquals |
||||||
|
|
||||||
|
object JaggrabRequestEncoderTest { |
||||||
|
@Test |
||||||
|
fun testEncode() { |
||||||
|
val channel = EmbeddedChannel(JaggrabRequestEncoder) |
||||||
|
channel.writeOutbound(JaggrabRequest("/runescape.pack200")) |
||||||
|
|
||||||
|
val actual = channel.readOutbound<String>() |
||||||
|
assertEquals("JAGGRAB /runescape.pack200\n\n", actual) |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue