Package alexiil.mc.lib.net
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
,java.lang.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.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CheckingNetByteBuf.InvalidNetTypeException
Unchecked exception that's thrown when one of the types doesn't match.static class
CheckingNetByteBuf.NetMethod
A networking related method that wrote data to the buffer.Nested classes/interfaces inherited from class alexiil.mc.lib.net.NetByteBuf
NetByteBuf.SavedReaderIndex
-
Field Summary
Fields inherited from class alexiil.mc.lib.net.NetByteBuf
EMPTY_BUFFER, MAX_VAR_S_INT_1_BYTE, MAX_VAR_S_INT_2_BYTES, MAX_VAR_S_INT_3_BYTES, MAX_VAR_S_INT_4_BYTES, MAX_VAR_U_INT_1_BYTE, MAX_VAR_U_INT_2_BYTES, MAX_VAR_U_INT_3_BYTES, MAX_VAR_U_INT_4_BYTES, MIN_VAR_S_INT_1_BYTE, MIN_VAR_S_INT_2_BYTES, MIN_VAR_S_INT_3_BYTES, MIN_VAR_S_INT_4_BYTES, MIN_VAR_U_INT_SMALL
-
Constructor Summary
Constructors Constructor Description CheckingNetByteBuf(NetByteBuf wrapped, NetByteBuf typeData)
-
Method Summary
Modifier and Type Method Description int
getCountRead()
int
getCountWrite()
boolean
hasTypeData()
boolean
isRecordingMarkers()
net.minecraft.util.hit.BlockHitResult
readBlockHitResult()
net.minecraft.util.math.BlockPos
readBlockPos()
boolean
readBoolean()
Reads a single boolean from some position in this buffer.byte
readByte()
CheckingNetByteBuf
readBytes(byte[] dst)
CheckingNetByteBuf
readBytes(byte[] dst, int dstIndex, int length)
CheckingNetByteBuf
readBytes(io.netty.buffer.ByteBuf byteBuf)
CheckingNetByteBuf
readBytes(io.netty.buffer.ByteBuf byteBuf, int length)
char
readChar()
net.minecraft.nbt.CompoundTag
readCompoundTag()
double
readDouble()
double
readDoubleLE()
<E extends java.lang.Enum<E>>
EreadEnumConstant(java.lang.Class<E> enumClass)
int
readFixedBits(int length)
float
readFloat()
float
readFloatLE()
int
readInt()
int
readIntLE()
long
readLong()
long
readLongLE()
void
readMarker(java.lang.String id)
Reads a "marker" for debug purposes.void
readMarkerId(int expected)
void
readMarkerId(IMsgReadCtx ctx, TreeNetIdBase netId)
int
readMedium()
int
readMediumLE()
short
readShort()
short
readShortLE()
java.lang.String
readString()
Reads a string of up toShort.MAX_VALUE
length.java.lang.String
readString(int maxLength)
short
readUnsignedByte()
long
readUnsignedInt()
long
readUnsignedIntLE()
int
readUnsignedMedium()
int
readUnsignedMediumLE()
int
readUnsignedShort()
int
readUnsignedShortLE()
int
readVarInt()
Reads out an integer using a variable number of bytes, assuming it was written byNetByteBuf.writeVarInt(int)
long
readVarLong()
int
readVarUnsignedInt()
Exposes the vanilla method for reading an unsigned integer using a variable number of bytes.long
readVarUnsignedLong()
Exposes the vanilla method for reading an unsigned long integer using a variable number of bytes.void
recordReads()
Call this to make this use the typeData buffer to store the types read rather than written.void
writeBlockHitResult(net.minecraft.util.hit.BlockHitResult blockHitResult)
CheckingNetByteBuf
writeBlockPos(net.minecraft.util.math.BlockPos pos)
CheckingNetByteBuf
writeBoolean(boolean flag)
Writes a single boolean out to some position in this buffer.CheckingNetByteBuf
writeByte(int i)
CheckingNetByteBuf
writeBytes(byte[] src)
CheckingNetByteBuf
writeBytes(byte[] src, int srcIndex, int length)
CheckingNetByteBuf
writeBytes(io.netty.buffer.ByteBuf byteBuf)
CheckingNetByteBuf
writeBytes(io.netty.buffer.ByteBuf byteBuf, int length)
CheckingNetByteBuf
writeChar(int i)
CheckingNetByteBuf
writeCompoundTag(net.minecraft.nbt.CompoundTag compoundTag)
CheckingNetByteBuf
writeDouble(double d)
CheckingNetByteBuf
writeDoubleLE(double value)
CheckingNetByteBuf
writeEnumConstant(java.lang.Enum<?> value)
CheckingNetByteBuf
writeFixedBits(int value, int length)
Writes a fixed number of bits out to the stream.CheckingNetByteBuf
writeFloat(float f)
CheckingNetByteBuf
writeFloatLE(float value)
CheckingNetByteBuf
writeInt(int i)
CheckingNetByteBuf
writeIntLE(int i)
CheckingNetByteBuf
writeLong(long l)
CheckingNetByteBuf
writeLongLE(long l)
void
writeMarker(java.lang.String id)
Writes a "marker" for debug purposes.void
writeMarkerId(int id)
CheckingNetByteBuf
writeMedium(int i)
CheckingNetByteBuf
writeMediumLE(int i)
CheckingNetByteBuf
writeShort(int i)
CheckingNetByteBuf
writeShortLE(int i)
CheckingNetByteBuf
writeString(java.lang.String string)
CheckingNetByteBuf
writeString(java.lang.String string, int maxLength)
CheckingNetByteBuf
writeVarInt(int ival)
Writes out an integer using a variable number of bytes.CheckingNetByteBuf
writeVarLong(long lval)
Writes out a long integer using a variable number of bytes.CheckingNetByteBuf
writeVarUnsignedInt(int ival)
Exposes the vanilla method for writing out an unsigned integer using a variable number of bytes.CheckingNetByteBuf
writeVarUnsignedLong(long lval)
Exposes the vanilla method for writing out an unsigned long integer using a variable number of bytes.Methods inherited from class alexiil.mc.lib.net.NetByteBuf
asNetByteBuf, buffer, buffer, clear, copy, markReaderIndex, readBytes, readIdentifier, readIdentifierOrNull, readIdentifierSafe, resetReaderIndex, resetReaderIndex, saveReaderIndex, writeIdentifier
Methods inherited from class net.minecraft.network.PacketByteBuf
alloc, array, arrayOffset, asReadOnly, bytesBefore, bytesBefore, bytesBefore, capacity, capacity, compareTo, copy, decode, discardReadBytes, discardSomeReadBytes, duplicate, encode, ensureWritable, ensureWritable, equals, forEachByte, forEachByte, forEachByteDesc, forEachByteDesc, getBoolean, getByte, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getBytes, getChar, getCharSequence, getDouble, getFloat, getInt, getIntLE, getLong, getLongLE, getMedium, getMediumLE, getShort, getShortLE, getUnsignedByte, getUnsignedInt, getUnsignedIntLE, getUnsignedMedium, getUnsignedMediumLE, getUnsignedShort, getUnsignedShortLE, getVarIntSizeBytes, hasArray, hashCode, hasMemoryAddress, indexOf, internalNioBuffer, isDirect, isReadable, isReadable, isReadOnly, isWritable, isWritable, markWriterIndex, maxCapacity, maxWritableBytes, memoryAddress, method_30616, method_30617, nioBuffer, nioBuffer, nioBufferCount, nioBuffers, nioBuffers, order, order, readableBytes, readByteArray, readByteArray, readBytes, readBytes, readBytes, readBytes, readBytes, readCharSequence, readChunkSectionPos, readDate, readerIndex, readerIndex, readIntArray, readIntArray, readItemStack, readLongArray, readLongArray, readRetainedSlice, readSlice, readText, readUuid, refCnt, release, release, resetWriterIndex, retain, retain, retainedDuplicate, retainedSlice, retainedSlice, setBoolean, setByte, setBytes, setBytes, setBytes, setBytes, setBytes, setBytes, setBytes, setBytes, setBytes, setChar, setCharSequence, setDouble, setFloat, setIndex, setInt, setIntLE, setLong, setLongLE, setMedium, setMediumLE, setShort, setShortLE, setZero, skipBytes, slice, slice, toString, toString, toString, touch, touch, unwrap, writableBytes, writeByteArray, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeCharSequence, writeDate, writeIntArray, writeItemStack, writeLongArray, writerIndex, writerIndex, writeText, writeUuid, writeZero
-
Constructor Details
-
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.
-
readMarkerId
public void readMarkerId(int expected) -
readMarkerId
-
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 classNetByteBuf
-
writeBoolean
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 classNetByteBuf
-
readByte
public byte readByte()- Overrides:
readByte
in classnet.minecraft.network.PacketByteBuf
-
readUnsignedByte
public short readUnsignedByte()- Overrides:
readUnsignedByte
in classnet.minecraft.network.PacketByteBuf
-
writeByte
- Overrides:
writeByte
in classnet.minecraft.network.PacketByteBuf
-
readShort
public short readShort()- Overrides:
readShort
in classnet.minecraft.network.PacketByteBuf
-
readUnsignedShort
public int readUnsignedShort()- Overrides:
readUnsignedShort
in classnet.minecraft.network.PacketByteBuf
-
writeShort
- Overrides:
writeShort
in classnet.minecraft.network.PacketByteBuf
-
readMedium
public int readMedium()- Overrides:
readMedium
in classnet.minecraft.network.PacketByteBuf
-
readUnsignedMedium
public int readUnsignedMedium()- Overrides:
readUnsignedMedium
in classnet.minecraft.network.PacketByteBuf
-
writeMedium
- Overrides:
writeMedium
in classnet.minecraft.network.PacketByteBuf
-
readInt
public int readInt()- Overrides:
readInt
in classnet.minecraft.network.PacketByteBuf
-
readUnsignedInt
public long readUnsignedInt()- Overrides:
readUnsignedInt
in classnet.minecraft.network.PacketByteBuf
-
writeInt
- Overrides:
writeInt
in classnet.minecraft.network.PacketByteBuf
-
readLong
public long readLong()- Overrides:
readLong
in classnet.minecraft.network.PacketByteBuf
-
writeLong
- Overrides:
writeLong
in classnet.minecraft.network.PacketByteBuf
-
readShortLE
public short readShortLE()- Overrides:
readShortLE
in classnet.minecraft.network.PacketByteBuf
-
readUnsignedShortLE
public int readUnsignedShortLE()- Overrides:
readUnsignedShortLE
in classnet.minecraft.network.PacketByteBuf
-
writeShortLE
- Overrides:
writeShortLE
in classnet.minecraft.network.PacketByteBuf
-
readMediumLE
public int readMediumLE()- Overrides:
readMediumLE
in classnet.minecraft.network.PacketByteBuf
-
readUnsignedMediumLE
public int readUnsignedMediumLE()- Overrides:
readUnsignedMediumLE
in classnet.minecraft.network.PacketByteBuf
-
writeMediumLE
- Overrides:
writeMediumLE
in classnet.minecraft.network.PacketByteBuf
-
readIntLE
public int readIntLE()- Overrides:
readIntLE
in classnet.minecraft.network.PacketByteBuf
-
readUnsignedIntLE
public long readUnsignedIntLE()- Overrides:
readUnsignedIntLE
in classnet.minecraft.network.PacketByteBuf
-
writeIntLE
- Overrides:
writeIntLE
in classnet.minecraft.network.PacketByteBuf
-
readLongLE
public long readLongLE()- Overrides:
readLongLE
in classnet.minecraft.network.PacketByteBuf
-
writeLongLE
- Overrides:
writeLongLE
in classnet.minecraft.network.PacketByteBuf
-
readFloat
public float readFloat()- Overrides:
readFloat
in classnet.minecraft.network.PacketByteBuf
-
writeFloat
- Overrides:
writeFloat
in classnet.minecraft.network.PacketByteBuf
-
readFloatLE
public float readFloatLE()- Overrides:
readFloatLE
in classio.netty.buffer.ByteBuf
-
writeFloatLE
- Overrides:
writeFloatLE
in classio.netty.buffer.ByteBuf
-
readDouble
public double readDouble()- Overrides:
readDouble
in classnet.minecraft.network.PacketByteBuf
-
writeDouble
- Overrides:
writeDouble
in classnet.minecraft.network.PacketByteBuf
-
readDoubleLE
public double readDoubleLE()- Overrides:
readDoubleLE
in classio.netty.buffer.ByteBuf
-
writeDoubleLE
- Overrides:
writeDoubleLE
in classio.netty.buffer.ByteBuf
-
readChar
public char readChar()- Overrides:
readChar
in classnet.minecraft.network.PacketByteBuf
-
writeChar
- Overrides:
writeChar
in classnet.minecraft.network.PacketByteBuf
-
readBytes
- Overrides:
readBytes
in classnet.minecraft.network.PacketByteBuf
-
writeBytes
- Overrides:
writeBytes
in classnet.minecraft.network.PacketByteBuf
-
readBytes
- Overrides:
readBytes
in classnet.minecraft.network.PacketByteBuf
-
writeBytes
- Overrides:
writeBytes
in classnet.minecraft.network.PacketByteBuf
-
readBytes
- Overrides:
readBytes
in classnet.minecraft.network.PacketByteBuf
-
writeBytes
- Overrides:
writeBytes
in classnet.minecraft.network.PacketByteBuf
-
readBytes
- Overrides:
readBytes
in classnet.minecraft.network.PacketByteBuf
-
writeBytes
- Overrides:
writeBytes
in classnet.minecraft.network.PacketByteBuf
-
readBlockPos
public net.minecraft.util.math.BlockPos readBlockPos()Description copied from class:NetByteBuf
- Overrides:
readBlockPos
in classNetByteBuf
-
writeBlockPos
Description copied from class:NetByteBuf
- Overrides:
writeBlockPos
in classNetByteBuf
-
readBlockHitResult
public net.minecraft.util.hit.BlockHitResult readBlockHitResult()- Overrides:
readBlockHitResult
in classnet.minecraft.network.PacketByteBuf
-
writeBlockHitResult
public void writeBlockHitResult(net.minecraft.util.hit.BlockHitResult blockHitResult)- Overrides:
writeBlockHitResult
in classnet.minecraft.network.PacketByteBuf
-
readCompoundTag
public net.minecraft.nbt.CompoundTag readCompoundTag()- Overrides:
readCompoundTag
in classnet.minecraft.network.PacketByteBuf
-
writeCompoundTag
- Overrides:
writeCompoundTag
in classnet.minecraft.network.PacketByteBuf
-
readString
public java.lang.String readString()Description copied from class:NetByteBuf
Reads a string of up toShort.MAX_VALUE
length.NOTE: This is just
PacketByteBuf.readString()
but available on the server as well.- Overrides:
readString
in classNetByteBuf
-
writeString
- Overrides:
writeString
in classnet.minecraft.network.PacketByteBuf
-
readString
public java.lang.String readString(int maxLength)- Overrides:
readString
in classnet.minecraft.network.PacketByteBuf
-
writeString
- Overrides:
writeString
in classnet.minecraft.network.PacketByteBuf
-
readEnumConstant
public <E extends java.lang.Enum<E>> E readEnumConstant(java.lang.Class<E> enumClass)- Overrides:
readEnumConstant
in classNetByteBuf
-
writeEnumConstant
- Overrides:
writeEnumConstant
in classNetByteBuf
-
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 thanpow(2, 8 * 3 - 1)
()- Overrides:
readVarUnsignedInt
in classNetByteBuf
-
writeVarUnsignedInt
Description copied from class:NetByteBuf
Exposes the vanilla method for writing out an unsigned integer using a variable number of bytes.- 1 byte for
NetByteBuf.MIN_VAR_U_INT_SMALL
toNetByteBuf.MAX_VAR_S_INT_1_BYTE
- 2 bytes for
NetByteBuf.MIN_VAR_U_INT_SMALL
toNetByteBuf.MAX_VAR_S_INT_2_BYTES
- 3 bytes for
NetByteBuf.MIN_VAR_U_INT_SMALL
toNetByteBuf.MAX_VAR_S_INT_3_BYTES
- 4 bytes for
NetByteBuf.MIN_VAR_U_INT_SMALL
toNetByteBuf.MAX_VAR_S_INT_4_BYTES
- 5 bytes for
Integer.MIN_VALUE
toInteger.MAX_VALUE
Unlike
NetByteBuf.writeVarInt(int)
this only uses less than 5 bytes for non-negative integers less thanpow(2, 8 * 3 - 1)
()- Overrides:
writeVarUnsignedInt
in classNetByteBuf
- 1 byte for
-
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 thanpow(2, 8 * 7 - 1)
()- Overrides:
readVarUnsignedLong
in classNetByteBuf
-
writeVarUnsignedLong
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 thanpow(2, 8 * 7 - 1)
()- Overrides:
writeVarUnsignedLong
in classNetByteBuf
-
readFixedBits
public int readFixedBits(int length) throws java.lang.IllegalArgumentException- Overrides:
readFixedBits
in classNetByteBuf
- Parameters:
length
- The number of bits to read.- Returns:
- The read bits, compacted into an int.
- Throws:
java.lang.IllegalArgumentException
- if the length argument was less than 1 or greater than 32.
-
writeFixedBits
public CheckingNetByteBuf writeFixedBits(int value, int length) throws java.lang.IllegalArgumentExceptionDescription copied from class:NetByteBuf
Writes a fixed number of bits out to the stream.- Overrides:
writeFixedBits
in classNetByteBuf
- Parameters:
value
- the value to write out.length
- The number of bits to write.- Returns:
- This buffer.
- Throws:
java.lang.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 byNetByteBuf.writeVarInt(int)
- Overrides:
readVarInt
in classNetByteBuf
-
writeVarInt
Description copied from class:NetByteBuf
Writes out an integer using a variable number of bytes.- 1 byte for
NetByteBuf.MIN_VAR_S_INT_1_BYTE
toNetByteBuf.MAX_VAR_S_INT_1_BYTE
- 2 bytes for
NetByteBuf.MIN_VAR_S_INT_2_BYTES
toNetByteBuf.MAX_VAR_S_INT_2_BYTES
- 3 bytes for
NetByteBuf.MIN_VAR_S_INT_3_BYTES
toNetByteBuf.MAX_VAR_S_INT_3_BYTES
- 4 bytes for
NetByteBuf.MIN_VAR_S_INT_4_BYTES
toNetByteBuf.MAX_VAR_S_INT_4_BYTES
- 5 bytes for
Integer.MIN_VALUE
toInteger.MAX_VALUE
Unlike vanilla this doesn't use 5 bytes for all negative numbers.
- Overrides:
writeVarInt
in classNetByteBuf
- 1 byte for
-
readVarLong
public long readVarLong()- Overrides:
readVarLong
in classNetByteBuf
-
writeVarLong
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 classNetByteBuf
-
isRecordingMarkers
public boolean isRecordingMarkers()- Overrides:
isRecordingMarkers
in classNetByteBuf
- Returns:
- True if
NetByteBuf.writeMarker(String)
actually does anything.
-
readMarker
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 classNetByteBuf
- Throws:
InvalidInputDataException
-
writeMarker
public void writeMarker(java.lang.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 classNetByteBuf
-