Add method for peeking at the version trailer

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 2 years ago
parent 5ac5ae76f3
commit ef2919761d
  1. 8
      cache/src/main/kotlin/org/openrs2/cache/VersionTrailer.kt
  2. 17
      cache/src/test/kotlin/org/openrs2/cache/VersionTrailerTest.kt

@ -3,6 +3,14 @@ package org.openrs2.cache
import io.netty.buffer.ByteBuf
public object VersionTrailer {
public fun peek(buf: ByteBuf): Int? {
return if (buf.readableBytes() >= 2) {
buf.getUnsignedShort(buf.writerIndex() - 2)
} else {
null
}
}
public fun strip(buf: ByteBuf): Int? {
return if (buf.readableBytes() >= 2) {
val index = buf.writerIndex() - 2

@ -8,6 +8,23 @@ import kotlin.test.assertEquals
import kotlin.test.assertNull
class VersionTrailerTest {
@Test
fun testPeek() {
assertNull(VersionTrailer.peek(Unpooled.EMPTY_BUFFER))
wrappedBuffer(0).use { buf ->
assertNull(VersionTrailer.peek(buf))
}
wrappedBuffer(0x12, 0x34).use { buf ->
assertEquals(0x1234, VersionTrailer.peek(buf))
}
wrappedBuffer(0x12, 0x34, 0x56).use { buf ->
assertEquals(0x3456, VersionTrailer.peek(buf))
}
}
@Test
fun testStrip() {
assertNull(VersionTrailer.strip(Unpooled.EMPTY_BUFFER))

Loading…
Cancel
Save