Class CheckingNetByteBuf

java.lang.Object
io.netty.buffer.ByteBuf
net.minecraft.network.PacketByteBuf
alexiil.mc.lib.net.NetByteBuf
alexiil.mc.lib.net.CheckingNetByteBuf
All Implemented Interfaces:
io.netty.util.ReferenceCounted, Comparable<io.netty.buffer.ByteBuf>

public class CheckingNetByteBuf extends NetByteBuf
Debug variant of NetByteBuf that writes the method calls to ensure that it's a perfect mirror. This uses a separate data buffer for reading & writing types, which can be null if no type data is present.
  • Constructor Details

    • CheckingNetByteBuf

      public CheckingNetByteBuf(NetByteBuf wrapped, @Nullable NetByteBuf typeData)
  • Method Details

    • recordReads

      public void recordReads()
      Call this to make this use the typeData buffer to store the types read rather than written. Useful only if the type data wasn't provided by the writer.
    • getCountRead

      public int getCountRead()
      Returns:
      The number of read calls made.
    • getCountWrite

      public int getCountWrite()
      Returns:
      The number of write calls made.
    • getBitWriterIndex

      public int getBitWriterIndex()
      Description copied from class: NetByteBuf
      Bit version of PacketByteBuf.writerIndex().
      Overrides:
      getBitWriterIndex in class NetByteBuf
    • getBitReaderIndex

      public int getBitReaderIndex()
      Description copied from class: NetByteBuf
      Bit version of PacketByteBuf.readerIndex().
      Overrides:
      getBitReaderIndex in class NetByteBuf
    • readMarkerId

      public void readMarkerId(int expected)
    • readMarkerId

      public void readMarkerId(IMsgReadCtx ctx, TreeNetIdBase netId)
    • writeMarkerId

      public void writeMarkerId(int id)
    • hasTypeData

      public boolean hasTypeData()
    • readBoolean

      public boolean readBoolean()
      Description copied from class: NetByteBuf
      Reads a single boolean from some position in this buffer. The boolean flag might be read from a new byte (increasing the readerIndex) or it might be read from a previous byte that was read with a previous call to this method.
      Overrides:
      readBoolean in class NetByteBuf
    • writeBoolean

      public CheckingNetByteBuf writeBoolean(boolean flag)
      Description copied from class: NetByteBuf
      Writes a single boolean out to some position in this buffer. The boolean flag might be written to a new byte (increasing the writerIndex) or it might be added to an existing byte that was written with a previous call to this method.
      Overrides:
      writeBoolean in class NetByteBuf
    • readByte

      public byte readByte()
      Overrides:
      readByte in class net.minecraft.network.PacketByteBuf
    • readUnsignedByte

      public short readUnsignedByte()
      Overrides:
      readUnsignedByte in class net.minecraft.network.PacketByteBuf
    • writeByte

      public CheckingNetByteBuf writeByte(int i)
      Overrides:
      writeByte in class net.minecraft.network.PacketByteBuf
    • readShort

      public short readShort()
      Overrides:
      readShort in class net.minecraft.network.PacketByteBuf
    • readUnsignedShort

      public int readUnsignedShort()
      Overrides:
      readUnsignedShort in class net.minecraft.network.PacketByteBuf
    • writeShort

      public CheckingNetByteBuf writeShort(int i)
      Overrides:
      writeShort in class net.minecraft.network.PacketByteBuf
    • readMedium

      public int readMedium()
      Overrides:
      readMedium in class net.minecraft.network.PacketByteBuf
    • readUnsignedMedium

      public int readUnsignedMedium()
      Overrides:
      readUnsignedMedium in class net.minecraft.network.PacketByteBuf
    • writeMedium

      public CheckingNetByteBuf writeMedium(int i)
      Overrides:
      writeMedium in class net.minecraft.network.PacketByteBuf
    • readInt

      public int readInt()
      Overrides:
      readInt in class net.minecraft.network.PacketByteBuf
    • readUnsignedInt

      public long readUnsignedInt()
      Overrides:
      readUnsignedInt in class net.minecraft.network.PacketByteBuf
    • writeInt

      public CheckingNetByteBuf writeInt(int i)
      Overrides:
      writeInt in class net.minecraft.network.PacketByteBuf
    • readLong

      public long readLong()
      Overrides:
      readLong in class net.minecraft.network.PacketByteBuf
    • writeLong

      public CheckingNetByteBuf writeLong(long l)
      Overrides:
      writeLong in class net.minecraft.network.PacketByteBuf
    • readShortLE

      public short readShortLE()
      Overrides:
      readShortLE in class net.minecraft.network.PacketByteBuf
    • readUnsignedShortLE

      public int readUnsignedShortLE()
      Overrides:
      readUnsignedShortLE in class net.minecraft.network.PacketByteBuf
    • writeShortLE

      public CheckingNetByteBuf writeShortLE(int i)
      Overrides:
      writeShortLE in class net.minecraft.network.PacketByteBuf
    • readMediumLE

      public int readMediumLE()
      Overrides:
      readMediumLE in class net.minecraft.network.PacketByteBuf
    • readUnsignedMediumLE

      public int readUnsignedMediumLE()
      Overrides:
      readUnsignedMediumLE in class net.minecraft.network.PacketByteBuf
    • writeMediumLE

      public CheckingNetByteBuf writeMediumLE(int i)
      Overrides:
      writeMediumLE in class net.minecraft.network.PacketByteBuf
    • readIntLE

      public int readIntLE()
      Overrides:
      readIntLE in class net.minecraft.network.PacketByteBuf
    • readUnsignedIntLE

      public long readUnsignedIntLE()
      Overrides:
      readUnsignedIntLE in class net.minecraft.network.PacketByteBuf
    • writeIntLE

      public CheckingNetByteBuf writeIntLE(int i)
      Overrides:
      writeIntLE in class net.minecraft.network.PacketByteBuf
    • readLongLE

      public long readLongLE()
      Overrides:
      readLongLE in class net.minecraft.network.PacketByteBuf
    • writeLongLE

      public CheckingNetByteBuf writeLongLE(long l)
      Overrides:
      writeLongLE in class net.minecraft.network.PacketByteBuf
    • readFloat

      public float readFloat()
      Overrides:
      readFloat in class net.minecraft.network.PacketByteBuf
    • writeFloat

      public CheckingNetByteBuf writeFloat(float f)
      Overrides:
      writeFloat in class net.minecraft.network.PacketByteBuf
    • readFloatLE

      public float readFloatLE()
      Overrides:
      readFloatLE in class io.netty.buffer.ByteBuf
    • writeFloatLE

      public CheckingNetByteBuf writeFloatLE(float value)
      Overrides:
      writeFloatLE in class io.netty.buffer.ByteBuf
    • readDouble

      public double readDouble()
      Overrides:
      readDouble in class net.minecraft.network.PacketByteBuf
    • writeDouble

      public CheckingNetByteBuf writeDouble(double d)
      Overrides:
      writeDouble in class net.minecraft.network.PacketByteBuf
    • readDoubleLE

      public double readDoubleLE()
      Overrides:
      readDoubleLE in class io.netty.buffer.ByteBuf
    • writeDoubleLE

      public CheckingNetByteBuf writeDoubleLE(double value)
      Overrides:
      writeDoubleLE in class io.netty.buffer.ByteBuf
    • readChar

      public char readChar()
      Overrides:
      readChar in class net.minecraft.network.PacketByteBuf
    • writeChar

      public CheckingNetByteBuf writeChar(int i)
      Overrides:
      writeChar in class net.minecraft.network.PacketByteBuf
    • readBytes

      public final CheckingNetByteBuf readBytes(byte[] dst)
      Overrides:
      readBytes in class net.minecraft.network.PacketByteBuf
    • writeBytes

      public final CheckingNetByteBuf writeBytes(byte[] src)
      Overrides:
      writeBytes in class net.minecraft.network.PacketByteBuf
    • readBytes

      public CheckingNetByteBuf readBytes(byte[] dst, int dstIndex, int length)
      Overrides:
      readBytes in class net.minecraft.network.PacketByteBuf
    • writeBytes

      public CheckingNetByteBuf writeBytes(byte[] src, int srcIndex, int length)
      Overrides:
      writeBytes in class net.minecraft.network.PacketByteBuf
    • readBytes

      public final CheckingNetByteBuf readBytes(io.netty.buffer.ByteBuf byteBuf)
      Overrides:
      readBytes in class net.minecraft.network.PacketByteBuf
    • writeBytes

      public final CheckingNetByteBuf writeBytes(io.netty.buffer.ByteBuf byteBuf)
      Overrides:
      writeBytes in class net.minecraft.network.PacketByteBuf
    • readBytes

      public CheckingNetByteBuf readBytes(io.netty.buffer.ByteBuf byteBuf, int length)
      Overrides:
      readBytes in class net.minecraft.network.PacketByteBuf
    • writeBytes

      public CheckingNetByteBuf writeBytes(io.netty.buffer.ByteBuf byteBuf, int length)
      Overrides:
      writeBytes in class net.minecraft.network.PacketByteBuf
    • readBlockPos

      public net.minecraft.util.math.BlockPos readBlockPos()
      Description copied from class: NetByteBuf
      Reads a BlockPos using 3 NetByteBuf.readVarInt()s rather than BlockPos.fromLong(long).
      Overrides:
      readBlockPos in class NetByteBuf
    • writeBlockPos

      public CheckingNetByteBuf writeBlockPos(net.minecraft.util.math.BlockPos pos)
      Description copied from class: NetByteBuf
      Writes out a BlockPos using 3 NetByteBuf.writeVarInt(int)s rather than BlockPos.asLong().
      Overrides:
      writeBlockPos in class NetByteBuf
    • readBlockHitResult

      public net.minecraft.util.hit.BlockHitResult readBlockHitResult()
      Overrides:
      readBlockHitResult in class net.minecraft.network.PacketByteBuf
    • writeBlockHitResult

      public void writeBlockHitResult(net.minecraft.util.hit.BlockHitResult blockHitResult)
      Overrides:
      writeBlockHitResult in class net.minecraft.network.PacketByteBuf
    • readNbt

      public net.minecraft.nbt.NbtCompound readNbt()
      Overrides:
      readNbt in class net.minecraft.network.PacketByteBuf
    • writeNbt

      public CheckingNetByteBuf writeNbt(net.minecraft.nbt.NbtCompound compoundTag)
      Overrides:
      writeNbt in class net.minecraft.network.PacketByteBuf
    • readString

      public String readString()
      Description copied from class: NetByteBuf
      Reads a string of up to Short.MAX_VALUE length.

      NOTE: This is just PacketByteBuf.readString() but available on the server as well.

      Overrides:
      readString in class NetByteBuf
    • writeString

      public CheckingNetByteBuf writeString(String string)
      Overrides:
      writeString in class net.minecraft.network.PacketByteBuf
    • readString

      public String readString(int maxLength)
      Overrides:
      readString in class net.minecraft.network.PacketByteBuf
    • writeString

      public CheckingNetByteBuf writeString(String string, int maxLength)
      Overrides:
      writeString in class net.minecraft.network.PacketByteBuf
    • readEnumConstant

      public <E extends Enum<E>> E readEnumConstant(Class<E> enumClass)
      Overrides:
      readEnumConstant in class NetByteBuf
    • writeEnumConstant

      public CheckingNetByteBuf writeEnumConstant(Enum<?> value)
      Overrides:
      writeEnumConstant in class NetByteBuf
    • readVarUnsignedInt

      public int readVarUnsignedInt()
      Description copied from class: NetByteBuf
      Exposes the vanilla method for reading an unsigned integer using a variable number of bytes.

      Unlike NetByteBuf.readVarInt() this only uses less than 5 bytes for non-negative integers less than pow(2, 8 * 3 - 1) ()

      Overrides:
      readVarUnsignedInt in class NetByteBuf
    • writeVarUnsignedInt

      public CheckingNetByteBuf writeVarUnsignedInt(int ival)
      Description copied from class: NetByteBuf
      Exposes the vanilla method for writing out an unsigned integer using a variable number of bytes.

      Unlike NetByteBuf.writeVarInt(int) this only uses less than 5 bytes for non-negative integers less than pow(2, 8 * 3 - 1) ()

      Overrides:
      writeVarUnsignedInt in class NetByteBuf
    • readVarUnsignedLong

      public long readVarUnsignedLong()
      Description copied from class: NetByteBuf
      Exposes the vanilla method for reading an unsigned long integer using a variable number of bytes.

      Unlike NetByteBuf.readVarInt() this only uses less than 9 bytes for non-negative integers less than pow(2, 8 * 7 - 1) ()

      Overrides:
      readVarUnsignedLong in class NetByteBuf
    • writeVarUnsignedLong

      public CheckingNetByteBuf writeVarUnsignedLong(long lval)
      Description copied from class: NetByteBuf
      Exposes the vanilla method for writing out an unsigned long integer using a variable number of bytes.

      Unlike NetByteBuf.writeVarInt(int) this only uses less than 9 bytes for non-negative integers less than pow(2, 8 * 7 - 1) ()

      Overrides:
      writeVarUnsignedLong in class NetByteBuf
    • readFixedBits

      public int readFixedBits(int length) throws IllegalArgumentException
      Overrides:
      readFixedBits in class NetByteBuf
      Parameters:
      length - The number of bits to read.
      Returns:
      The read bits, compacted into an int.
      Throws:
      IllegalArgumentException - if the length argument was less than 1 or greater than 32.
    • writeFixedBits

      public CheckingNetByteBuf writeFixedBits(int value, int length) throws IllegalArgumentException
      Description copied from class: NetByteBuf
      Writes a fixed number of bits out to the stream.
      Overrides:
      writeFixedBits in class NetByteBuf
      Parameters:
      value - the value to write out.
      length - The number of bits to write.
      Returns:
      This buffer.
      Throws:
      IllegalArgumentException - if the length argument was less than 1 or greater than 32.
    • readVarInt

      public int readVarInt()
      Description copied from class: NetByteBuf
      Reads out an integer using a variable number of bytes, assuming it was written by NetByteBuf.writeVarInt(int)
      Overrides:
      readVarInt in class NetByteBuf
    • writeVarInt

      public CheckingNetByteBuf writeVarInt(int ival)
      Description copied from class: NetByteBuf
      Writes out an integer using a variable number of bytes.

      Unlike vanilla this doesn't use 5 bytes for all negative numbers.

      Overrides:
      writeVarInt in class NetByteBuf
    • readVarLong

      public long readVarLong()
      Overrides:
      readVarLong in class NetByteBuf
    • writeVarLong

      public CheckingNetByteBuf writeVarLong(long lval)
      Description copied from class: NetByteBuf
      Writes out a long integer using a variable number of bytes.
      • 1 byte for -64 to 63
      • 2 bytes for -8,192 to 8,191
      • 3 bytes for -1,048,576 to 1,048,575
      • 4 bytes for -134,217,728 to 134,217,727

      Unlike vanilla this doesn't use 9 bytes for all negative numbers.

      Overrides:
      writeVarLong in class NetByteBuf
    • isRecordingMarkers

      public boolean isRecordingMarkers()
      Overrides:
      isRecordingMarkers in class NetByteBuf
      Returns:
      True if NetByteBuf.writeMarker(String) actually does anything.
    • readMarker

      public void readMarker(String id) throws InvalidInputDataException
      Description copied from class: NetByteBuf
      Reads a "marker" for debug purposes. If debugging is disabled then this won't do anything. Otherwise this will throw an exception if the marker ID's didn't match.
      Overrides:
      readMarker in class NetByteBuf
      Throws:
      InvalidInputDataException
    • writeMarker

      public void writeMarker(String id)
      Description copied from class: NetByteBuf
      Writes a "marker" for debug purposes. If debugging is disabled then this won't do anything.
      Overrides:
      writeMarker in class NetByteBuf