Make Container extend DefaultByteBufHolder

Implementing ReferenceCounted with delegation doesn't quite work, as the
methods returning ReferenceCounted are not overriden to return
Container. This can cause code inside Netty to unintentionally unwrap
the Container.

Signed-off-by: Graham <gpe@openrs2.dev>
pull/132/head
Graham 4 years ago
parent 9770bab86d
commit 3ca22ad180
  1. 6
      archive/src/main/java/dev/openrs2/archive/cache/CacheImporter.kt

@ -12,7 +12,7 @@ import dev.openrs2.db.Database
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufAllocator import io.netty.buffer.ByteBufAllocator
import io.netty.buffer.ByteBufUtil import io.netty.buffer.ByteBufUtil
import io.netty.util.ReferenceCounted import io.netty.buffer.DefaultByteBufHolder
import java.io.IOException import java.io.IOException
import java.sql.Connection import java.sql.Connection
import java.sql.Types import java.sql.Types
@ -25,8 +25,8 @@ public class CacheImporter @Inject constructor(
private val alloc: ByteBufAllocator private val alloc: ByteBufAllocator
) { ) {
private abstract class Container( private abstract class Container(
private val data: ByteBuf data: ByteBuf
) : ReferenceCounted by data { ) : DefaultByteBufHolder(data) {
val bytes: ByteArray = ByteBufUtil.getBytes(data, data.readerIndex(), data.readableBytes(), false) val bytes: ByteArray = ByteBufUtil.getBytes(data, data.readerIndex(), data.readableBytes(), false)
val crc32 = data.crc32() val crc32 = data.crc32()
val whirlpool = Whirlpool.whirlpool(bytes) val whirlpool = Whirlpool.whirlpool(bytes)

Loading…
Cancel
Save