Simplify getBytes and add tests for it

This commit is contained in:
P0nk
2021-06-21 21:45:06 +02:00
parent 6d02a95273
commit 4fd64884f2
3 changed files with 27 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package net.packet;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import java.awt.*;
@@ -13,10 +14,7 @@ public class ByteBufInPacket implements InPacket {
@Override
public byte[] getBytes() {
byte[] bytes = new byte[byteBuf.readableBytes()];
int readerIndex = byteBuf.readerIndex();
byteBuf.getBytes(readerIndex, bytes);
return bytes;
return ByteBufUtil.getBytes(byteBuf);
}
@Override

View File

@@ -1,6 +1,7 @@
package net.packet;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import net.jcip.annotations.NotThreadSafe;
import net.opcodes.SendOpcode;
@@ -25,10 +26,7 @@ public class ByteBufOutPacket implements OutPacket {
@Override
public byte[] getBytes() {
byte[] bytes = new byte[byteBuf.readableBytes()];
int readerIndex = byteBuf.readerIndex();
byteBuf.getBytes(readerIndex, bytes);
return bytes;
return ByteBufUtil.getBytes(byteBuf);
}
@Override