mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Allow Netty to automatically maintain our internal usages of ByteBuf
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user