1package com.runehive.net.packet;
3import com.runehive.net.codec.ByteModification;
4import com.runehive.net.codec.ByteOrder;
5import io.netty.buffer.ByteBuf;
6import io.netty.buffer.DefaultByteBufHolder;
51 this.size =
payload.readableBytes();
135 int value =
payload.readByte();
153 return signed ? value : value & 0xFF;
271 throw new UnsupportedOperationException(
"Inverse-middle-endian short is impossible!");
274 throw new UnsupportedOperationException(
"Middle-endian short " +
"is impossible!");
281 return signed ? value : value & 0xFFFF;
395 return (
int) (
signed ? value : value & 0xFFFFFFFFL);
481 value |= (long)
readByte(
false) << 56L;
482 value |= (long)
readByte(
false) << 48L;
483 value |= (long)
readByte(
false) << 40L;
484 value |= (long)
readByte(
false) << 32L;
485 value |= (long)
readByte(
false) << 24L;
486 value |= (long)
readByte(
false) << 16L;
487 value |= (long)
readByte(
false) << 8L;
493 throw new UnsupportedOperationException(
"Middle and " +
"inverse-middle value types not supported!");
497 value |= (long)
readByte(
false) << 8L;
498 value |= (long)
readByte(
false) << 16L;
499 value |= (long)
readByte(
false) << 24L;
500 value |= (long)
readByte(
false) << 32L;
501 value |= (long)
readByte(
false) << 40L;
502 value |= (long)
readByte(
false) << 48L;
503 value |= (long)
readByte(
false) << 56L;
507 return signed ? value : value & 0xFFFFFFFFL;
534 byte[] data =
new byte[amount];
535 for (
int i = 0; i < amount; i++) {
565 byte[] data =
new byte[amount];
567 int dataPosition = 0;
569 for (
int index =
payload.readerIndex() + amount - 1; index >=
payload.readerIndex(); index--) {
570 int value =
payload.getByte(index);
590 data[dataPosition++] = (byte) value;
601 final StringBuilder bldr =
new StringBuilder();
604 bldr.append((
char) b);
606 return bldr.toString();
611 return String.format(
"[opcode=%d], [type=%s], [size= %d]",
opcode,
header.name(),
size);
byte[] readBytes(int amount)
Reads the amount of bytes into the array, starting at the current position.
int readShort(boolean signed, ByteModification mod)
Reads a short value from the payload in BIG order.
int readByte(boolean signed)
Reads a STANDARD byte from the payload.
int readShort(boolean signed, ByteOrder order)
Reads a STANDARD short value from the payload.
final PacketType header
The header for this packet.
int readShort(ByteOrder order, ByteModification mod)
Reads a signed short value from the payload.
int readShort(ByteOrder order)
Reads a STANDARD signed short value from the payload.
int getOpcode()
Gets the opcode.
int readShort(boolean signed, ByteOrder order, ByteModification mod)
Reads a short value from the payload.
int readInt(boolean signed, ByteOrder order, ByteModification mod)
Reads an integer value from the payload.
final ByteBuf payload
The buffer that contains the data for this packet.
long readLong()
Reads a STANDARD signed long value from the payload in BIG order.
int readByte(ByteModification mod)
Reads a signed byte from the payload.
int readShort(boolean signed)
Reads a STANDARD short value from the payload in BIG order.
ByteBuf getPayload()
Gets the payload.
PacketType getHeader()
Gets the type.
int readShort(ByteModification mod)
Reads a signed short value from the payload BIG order.
int readInt(boolean signed)
Reads a STANDARD integer value from the payload in BIG order.
long readLong(boolean signed, ByteOrder order, ByteModification mod)
Reads a long value from the payload.
byte[] readBytesReverse(int amount)
Reads a series of bytes in reverse.
String getRS2String()
Reads a RuneScape string.
int readByte()
Reads a STANDARD signed byte from the payload.
long readLong(boolean signed)
Reads a STANDARD long value from the payload in BIG order.
int readInt(boolean signed, ByteOrder order)
Reads a STANDARD integer value from the payload.
byte[] readBytesReverse(int amount, ByteModification mod)
Reads a series of bytes in reverse.
int getSize()
Gets the size of this payload.
final int size
The size of this packet.
int readInt()
Reads a STANDARD signed integer value from the payload in BIG order.
final int opcode
The opcode for this packet.
long readLong(boolean signed, ByteOrder order)
Reads a STANDARD long value from the payload.
long readLong(ByteModification mod)
Reads a signed long value from the payload in BIG order.
long readLong(boolean signed, ByteModification mod)
Reads a long value from the payload in BIG order.
int readShort()
Reads a STANDARD signed short value from the payload in BIG order.
int readByte(boolean signed, ByteModification mod)
Reads a single byte from the payload.
GamePacket(final int opcode, final PacketType header, final ByteBuf payload)
Creates a GamePacket.
int readInt(ByteModification mod)
Reads a signed integer value from the payload in ByteOrder BIG order.
byte[] readBytes(int amount, ByteModification mod)
Reads a series of bytes from a buffer.
int readInt(boolean signed, ByteModification mod)
Reads an integer value from the payload in BIG order.
Represents RuneScape's custom value types.
Represents the order in which bytes are written.
Represents a type of packet.