Allow Netty to automatically maintain our internal usages of ByteBuf

This commit is contained in:
atomicint
2018-11-11 10:48:41 -05:00
parent 68361110d9
commit 3326dba3cd
8 changed files with 33 additions and 51 deletions
@@ -2,6 +2,7 @@ package org.apollo.net.codec.game;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import org.apollo.net.meta.PacketType;
/**
@@ -9,7 +10,7 @@ import org.apollo.net.meta.PacketType;
*
* @author Graham
*/
public final class GamePacket {
public final class GamePacket extends DefaultByteBufHolder {
/**
* The length.
@@ -21,11 +22,6 @@ public final class GamePacket {
*/
private final int opcode;
/**
* The payload.
*/
private final ByteBuf payload;
/**
* The packet type.
*/
@@ -39,10 +35,10 @@ public final class GamePacket {
* @param payload The payload.
*/
public GamePacket(int opcode, PacketType type, ByteBuf payload) {
super(payload);
this.opcode = opcode;
this.type = type;
length = payload.readableBytes();
this.payload = payload;
}
/**
@@ -63,15 +59,6 @@ public final class GamePacket {
return opcode;
}
/**
* Gets the payload.
*
* @return The payload.
*/
public ByteBuf getPayload() {
return payload;
}
/**
* Gets the packet type.
*
@@ -44,7 +44,7 @@ public final class GamePacketEncoder extends MessageToByteEncoder<GamePacket> {
} else if (type == PacketType.VARIABLE_SHORT) {
out.writeShort(payloadLength);
}
out.writeBytes(packet.getPayload());
out.writeBytes(packet.content());
}
}
@@ -34,7 +34,7 @@ public final class GamePacketReader {
* @param packet The packet.
*/
public GamePacketReader(GamePacket packet) {
buffer = packet.getPayload();
buffer = packet.content();
}
/**