1package com.osroyale.net.packet;
3import com.osroyale.net.codec.ByteModification;
4import com.osroyale.net.codec.ByteOrder;
5import io.netty.buffer.ByteBuf;
6import io.netty.buffer.DefaultByteBufHolder;
55 private final int opcode;
65 private final ByteBuf payload;
70 private final int size;
87 this.payload = payload;
88 this.size = payload.readableBytes();
133 return payload.readByte();
172 int value = payload.readByte();
190 return signed ? value : value & 0xFF;
200 return payload.readShort();
308 throw new UnsupportedOperationException(
"Inverse-middle-endian short is impossible!");
311 throw new UnsupportedOperationException(
"Middle-endian short " +
"is impossible!");
318 return signed ? value : value & 0xFFFF;
432 return (
int) (
signed ? value : value & 0xFFFFFFFFL);
518 value |= (long)
readByte(
false) << 56L;
519 value |= (long)
readByte(
false) << 48L;
520 value |= (long)
readByte(
false) << 40L;
521 value |= (long)
readByte(
false) << 32L;
522 value |= (long)
readByte(
false) << 24L;
523 value |= (long)
readByte(
false) << 16L;
524 value |= (long)
readByte(
false) << 8L;
530 throw new UnsupportedOperationException(
"Middle and " +
"inverse-middle value types not supported!");
534 value |= (long)
readByte(
false) << 8L;
535 value |= (long)
readByte(
false) << 16L;
536 value |= (long)
readByte(
false) << 24L;
537 value |= (long)
readByte(
false) << 32L;
538 value |= (long)
readByte(
false) << 40L;
539 value |= (long)
readByte(
false) << 48L;
540 value |= (long)
readByte(
false) << 56L;
544 return signed ? value : value & 0xFFFFFFFFL;
571 byte[] data =
new byte[amount];
572 for (
int i = 0; i < amount; i++) {
602 byte[] data =
new byte[amount];
604 int dataPosition = 0;
606 for (
int index = payload.readerIndex() + amount - 1; index >= payload.readerIndex(); index--) {
607 int value = payload.getByte(index);
627 data[dataPosition++] = (byte) value;
638 final StringBuilder bldr =
new StringBuilder();
640 while (payload.isReadable() && (b = payload.readByte()) != 10) {
641 bldr.append((
char) b);
643 return bldr.toString();
647 public String toString() {
648 return String.format(
"[opcode=%d], [type=%s], [size= %d]", opcode, header.name(), size);
int readInt(boolean signed, ByteModification mod)
int readShort(boolean signed, ByteOrder order)
int readShort(boolean signed, ByteModification mod)
byte[] readBytes(int amount, ByteModification mod)
int readInt(boolean signed, ByteOrder order)
int readByte(ByteModification mod)
int readShort(ByteOrder order, ByteModification mod)
int readShort(ByteModification mod)
long readLong(boolean signed)
int readInt(boolean signed)
int readByte(boolean signed)
int readByte(boolean signed, ByteModification mod)
int readInt(boolean signed, ByteOrder order, ByteModification mod)
byte[] readBytes(int amount)
int readShort(boolean signed)
long readLong(boolean signed, ByteOrder order)
long readLong(boolean signed, ByteOrder order, ByteModification mod)
int readInt(ByteModification mod)
int readShort(ByteOrder order)
long readLong(boolean signed, ByteModification mod)
byte[] readBytesReverse(int amount)
byte[] readBytesReverse(int amount, ByteModification mod)
int readShort(boolean signed, ByteOrder order, ByteModification mod)
GamePacket(final int opcode, final PacketType header, final ByteBuf payload)
long readLong(ByteModification mod)