Class NetByteBuf
- All Implemented Interfaces:
io.netty.util.ReferenceCounted,java.lang.Comparable<io.netty.buffer.ByteBuf>
- Direct Known Subclasses:
CheckingNetByteBuf
public class NetByteBuf
extends net.minecraft.network.PacketByteBuf
PacketByteBuf class that provides methods specific to "offset" reading and writing - like writing a
single bit to the stream, and auto-compacting it with similar bits into a single byte.
In addition this overrides a number of existing methods (like writeBoolean(boolean),
writeEnumConstant(Enum), writeVarInt(int), writeVarLong(long)
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNetByteBuf.SavedReaderIndex -
Field Summary
Fields Modifier and Type Field Description static NetByteBufEMPTY_BUFFERstatic intMAX_VAR_S_INT_1_BYTEstatic intMAX_VAR_S_INT_2_BYTESstatic intMAX_VAR_S_INT_3_BYTESstatic intMAX_VAR_S_INT_4_BYTESstatic intMAX_VAR_U_INT_1_BYTEstatic intMAX_VAR_U_INT_2_BYTESstatic intMAX_VAR_U_INT_3_BYTESstatic intMAX_VAR_U_INT_4_BYTESstatic intMIN_VAR_S_INT_1_BYTEstatic intMIN_VAR_S_INT_2_BYTESstatic intMIN_VAR_S_INT_3_BYTESstatic intMIN_VAR_S_INT_4_BYTESstatic intMIN_VAR_U_INT_SMALL -
Constructor Summary
Constructors Constructor Description NetByteBuf(io.netty.buffer.ByteBuf wrapped) -
Method Summary
Modifier and Type Method Description static NetByteBufasNetByteBuf(io.netty.buffer.ByteBuf buf)Returns the givenByteBufasNetByteBuf.static NetByteBufbuffer()static NetByteBufbuffer(int initialCapacity)NetByteBufclear()NetByteBufcopy()booleanisRecordingMarkers()NetByteBufmarkReaderIndex()net.minecraft.util.math.BlockPosreadBlockPos()booleanreadBoolean()Reads a single boolean from some position in this buffer.NetByteBufreadBytes(int length)<E extends java.lang.Enum<E>>
EreadEnumConstant(java.lang.Class<E> enumClass)intreadFixedBits(int length)net.minecraft.util.IdentifierreadIdentifier()Deprecated.BecausePacketByteBuf.readIdentifier()can throw anInvalidIdentifierException, butnet.minecraft.util.IdentifierreadIdentifierOrNull()LikereadIdentifierSafe(), but returns null instead of throwing an error if the read string was invalid.net.minecraft.util.IdentifierreadIdentifierSafe()Reads in a string, and tries to parse it as anIdentifier.voidreadMarker(java.lang.String id)Reads a "marker" for debug purposes.java.lang.StringreadString()Reads a string of up toShort.MAX_VALUElength.intreadVarInt()Reads out an integer using a variable number of bytes, assuming it was written bywriteVarInt(int)longreadVarLong()intreadVarUnsignedInt()Exposes the vanilla method for reading an unsigned integer using a variable number of bytes.longreadVarUnsignedLong()Exposes the vanilla method for reading an unsigned long integer using a variable number of bytes.NetByteBufresetReaderIndex()NetByteBufresetReaderIndex(NetByteBuf.SavedReaderIndex index)NetByteBuf.SavedReaderIndexsaveReaderIndex()NetByteBufwriteBlockPos(net.minecraft.util.math.BlockPos pos)NetByteBufwriteBoolean(boolean flag)Writes a single boolean out to some position in this buffer.NetByteBufwriteEnumConstant(java.lang.Enum<?> value)NetByteBufwriteFixedBits(int value, int length)Writes a fixed number of bits out to the stream.NetByteBufwriteIdentifier(net.minecraft.util.Identifier id)voidwriteMarker(java.lang.String id)Writes a "marker" for debug purposes.NetByteBufwriteVarInt(int ival)Writes out an integer using a variable number of bytes.NetByteBufwriteVarLong(long lval)Writes out a long integer using a variable number of bytes.NetByteBufwriteVarUnsignedInt(int ival)Exposes the vanilla method for writing out an unsigned integer using a variable number of bytes.NetByteBufwriteVarUnsignedLong(long lval)Exposes the vanilla method for writing out an unsigned long integer using a variable number of bytes.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, readBlockHitResult, readByte, readByteArray, readByteArray, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readChar, readCharSequence, readChunkSectionPos, readCompoundTag, readDate, readDouble, readerIndex, readerIndex, readFloat, readInt, readIntArray, readIntArray, readIntLE, readItemStack, readLong, readLongArray, readLongArray, readLongLE, readMedium, readMediumLE, readRetainedSlice, readShort, readShortLE, readSlice, readString, readText, readUnsignedByte, readUnsignedInt, readUnsignedIntLE, readUnsignedMedium, readUnsignedMediumLE, readUnsignedShort, readUnsignedShortLE, 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, writeBlockHitResult, writeByte, writeByteArray, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeChar, writeCharSequence, writeCompoundTag, writeDate, writeDouble, writeFloat, writeInt, writeIntArray, writeIntLE, writeItemStack, writeLong, writeLongArray, writeLongLE, writeMedium, writeMediumLE, writerIndex, writerIndex, writeShort, writeShortLE, writeString, writeString, writeText, writeUuid, writeZero
-
Field Details
-
EMPTY_BUFFER
-
MIN_VAR_S_INT_1_BYTE
public static final int MIN_VAR_S_INT_1_BYTE- See Also:
- Constant Field Values
-
MAX_VAR_S_INT_1_BYTE
public static final int MAX_VAR_S_INT_1_BYTE- See Also:
- Constant Field Values
-
MIN_VAR_S_INT_2_BYTES
public static final int MIN_VAR_S_INT_2_BYTES- See Also:
- Constant Field Values
-
MAX_VAR_S_INT_2_BYTES
public static final int MAX_VAR_S_INT_2_BYTES- See Also:
- Constant Field Values
-
MIN_VAR_S_INT_3_BYTES
public static final int MIN_VAR_S_INT_3_BYTES- See Also:
- Constant Field Values
-
MAX_VAR_S_INT_3_BYTES
public static final int MAX_VAR_S_INT_3_BYTES- See Also:
- Constant Field Values
-
MIN_VAR_S_INT_4_BYTES
public static final int MIN_VAR_S_INT_4_BYTES- See Also:
- Constant Field Values
-
MAX_VAR_S_INT_4_BYTES
public static final int MAX_VAR_S_INT_4_BYTES- See Also:
- Constant Field Values
-
MIN_VAR_U_INT_SMALL
public static final int MIN_VAR_U_INT_SMALL- See Also:
- Constant Field Values
-
MAX_VAR_U_INT_1_BYTE
public static final int MAX_VAR_U_INT_1_BYTE- See Also:
- Constant Field Values
-
MAX_VAR_U_INT_2_BYTES
public static final int MAX_VAR_U_INT_2_BYTES- See Also:
- Constant Field Values
-
MAX_VAR_U_INT_3_BYTES
public static final int MAX_VAR_U_INT_3_BYTES- See Also:
- Constant Field Values
-
MAX_VAR_U_INT_4_BYTES
public static final int MAX_VAR_U_INT_4_BYTES- See Also:
- Constant Field Values
-
-
Constructor Details
-
NetByteBuf
public NetByteBuf(io.netty.buffer.ByteBuf wrapped)
-
-
Method Details
-
buffer
- Returns:
- A new
NetByteBuffromUnpooled.buffer()
-
buffer
- Returns:
- A new
NetByteBuffromUnpooled.buffer(int)
-
asNetByteBuf
Returns the givenByteBufasNetByteBuf. if the given instance is already aNetByteBufthen the given buffer is returned (note that this may result in unexpected consequences if multiple read/write Boolean methods are called on the given buffer before you called this). -
copy
- Overrides:
copyin classnet.minecraft.network.PacketByteBuf
-
readBytes
- Overrides:
readBytesin classnet.minecraft.network.PacketByteBuf
-
clear
- Overrides:
clearin classnet.minecraft.network.PacketByteBuf
-
markReaderIndex
- Overrides:
markReaderIndexin classnet.minecraft.network.PacketByteBuf
-
resetReaderIndex
- Overrides:
resetReaderIndexin classnet.minecraft.network.PacketByteBuf
-
saveReaderIndex
-
resetReaderIndex
-
writeBoolean
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:
writeBooleanin classnet.minecraft.network.PacketByteBuf
-
readBoolean
public boolean readBoolean()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:
readBooleanin classnet.minecraft.network.PacketByteBuf
-
writeFixedBits
Writes a fixed number of bits out to the stream.- 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.
-
readFixedBits
public int readFixedBits(int length) throws java.lang.IllegalArgumentException- 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.
-
writeEnumConstant
- Overrides:
writeEnumConstantin classnet.minecraft.network.PacketByteBuf
-
readEnumConstant
public <E extends java.lang.Enum<E>> E readEnumConstant(java.lang.Class<E> enumClass)- Overrides:
readEnumConstantin classnet.minecraft.network.PacketByteBuf
-
writeBlockPos
- Overrides:
writeBlockPosin classnet.minecraft.network.PacketByteBuf
-
readBlockPos
public net.minecraft.util.math.BlockPos readBlockPos()- Overrides:
readBlockPosin classnet.minecraft.network.PacketByteBuf
-
writeVarInt
Writes out an integer using a variable number of bytes.- 1 byte for
MIN_VAR_S_INT_1_BYTEtoMAX_VAR_S_INT_1_BYTE - 2 bytes for
MIN_VAR_S_INT_2_BYTEStoMAX_VAR_S_INT_2_BYTES - 3 bytes for
MIN_VAR_S_INT_3_BYTEStoMAX_VAR_S_INT_3_BYTES - 4 bytes for
MIN_VAR_S_INT_4_BYTEStoMAX_VAR_S_INT_4_BYTES - 5 bytes for
Integer.MIN_VALUEtoInteger.MAX_VALUE
Unlike vanilla this doesn't use 5 bytes for all negative numbers.
- Overrides:
writeVarIntin classnet.minecraft.network.PacketByteBuf
- 1 byte for
-
readVarInt
public int readVarInt()Reads out an integer using a variable number of bytes, assuming it was written bywriteVarInt(int)- Overrides:
readVarIntin classnet.minecraft.network.PacketByteBuf
-
writeVarUnsignedInt
Exposes the vanilla method for writing out an unsigned integer using a variable number of bytes.- 1 byte for
MIN_VAR_U_INT_SMALLtoMAX_VAR_S_INT_1_BYTE - 2 bytes for
MIN_VAR_U_INT_SMALLtoMAX_VAR_S_INT_2_BYTES - 3 bytes for
MIN_VAR_U_INT_SMALLtoMAX_VAR_S_INT_3_BYTES - 4 bytes for
MIN_VAR_U_INT_SMALLtoMAX_VAR_S_INT_4_BYTES - 5 bytes for
Integer.MIN_VALUEtoInteger.MAX_VALUE
Unlike
writeVarInt(int)this only uses less than 5 bytes for non-negative integers less thanpow(2, 8 * 3 - 1)() - 1 byte for
-
readVarUnsignedInt
public int readVarUnsignedInt()Exposes the vanilla method for reading an unsigned integer using a variable number of bytes.Unlike
readVarInt()this only uses less than 5 bytes for non-negative integers less thanpow(2, 8 * 3 - 1)() -
writeVarLong
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:
writeVarLongin classnet.minecraft.network.PacketByteBuf
-
readVarLong
public long readVarLong()- Overrides:
readVarLongin classnet.minecraft.network.PacketByteBuf
-
writeVarUnsignedLong
Exposes the vanilla method for writing out an unsigned long integer using a variable number of bytes.Unlike
writeVarInt(int)this only uses less than 9 bytes for non-negative integers less thanpow(2, 8 * 7 - 1)() -
readVarUnsignedLong
public long readVarUnsignedLong()Exposes the vanilla method for reading an unsigned long integer using a variable number of bytes.Unlike
readVarInt()this only uses less than 9 bytes for non-negative integers less thanpow(2, 8 * 7 - 1)() -
writeIdentifier
- Overrides:
writeIdentifierin classnet.minecraft.network.PacketByteBuf
-
readIdentifier
@Deprecated public net.minecraft.util.Identifier readIdentifier()Deprecated.BecausePacketByteBuf.readIdentifier()can throw anInvalidIdentifierException, but- Overrides:
readIdentifierin classnet.minecraft.network.PacketByteBuf
-
readIdentifierSafe
Reads in a string, and tries to parse it as anIdentifier. If the string is a valid identifier then it is returned, however if it isn't thenInvalidInputDataExceptionis thrown.- Throws:
InvalidInputDataException- if the read string wasn't a validIdentifier.
-
readIdentifierOrNull
@Nullable public net.minecraft.util.Identifier readIdentifierOrNull()LikereadIdentifierSafe(), but returns null instead of throwing an error if the read string was invalid. -
readString
public java.lang.String readString()Reads a string of up toShort.MAX_VALUElength.NOTE: This is just
PacketByteBuf.readString()but available on the server as well.- Overrides:
readStringin classnet.minecraft.network.PacketByteBuf
-
isRecordingMarkers
public boolean isRecordingMarkers()- Returns:
- True if
writeMarker(String)actually does anything.
-
writeMarker
public void writeMarker(java.lang.String id)Writes a "marker" for debug purposes. If debugging is disabled then this won't do anything. -
readMarker
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.- Throws:
InvalidInputDataException
-