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 class
NetByteBuf.SavedReaderIndex
-
Field Summary
Fields Modifier and Type Field Description static NetByteBuf
EMPTY_BUFFER
static int
MAX_VAR_S_INT_1_BYTE
static int
MAX_VAR_S_INT_2_BYTES
static int
MAX_VAR_S_INT_3_BYTES
static int
MAX_VAR_S_INT_4_BYTES
static int
MAX_VAR_U_INT_1_BYTE
static int
MAX_VAR_U_INT_2_BYTES
static int
MAX_VAR_U_INT_3_BYTES
static int
MAX_VAR_U_INT_4_BYTES
static int
MIN_VAR_S_INT_1_BYTE
static int
MIN_VAR_S_INT_2_BYTES
static int
MIN_VAR_S_INT_3_BYTES
static int
MIN_VAR_S_INT_4_BYTES
static int
MIN_VAR_U_INT_SMALL
-
Constructor Summary
Constructors Constructor Description NetByteBuf(io.netty.buffer.ByteBuf wrapped)
-
Method Summary
Modifier and Type Method Description static NetByteBuf
asNetByteBuf(io.netty.buffer.ByteBuf buf)
Returns the givenByteBuf
asNetByteBuf
.static NetByteBuf
buffer()
static NetByteBuf
buffer(int initialCapacity)
NetByteBuf
clear()
NetByteBuf
copy()
boolean
isRecordingMarkers()
NetByteBuf
markReaderIndex()
net.minecraft.util.math.BlockPos
readBlockPos()
boolean
readBoolean()
Reads a single boolean from some position in this buffer.NetByteBuf
readBytes(int length)
<E extends java.lang.Enum<E>>
EreadEnumConstant(java.lang.Class<E> enumClass)
int
readFixedBits(int length)
net.minecraft.util.Identifier
readIdentifier()
Deprecated.BecausePacketByteBuf.readIdentifier()
can throw anInvalidIdentifierException
, butnet.minecraft.util.Identifier
readIdentifierOrNull()
LikereadIdentifierSafe()
, but returns null instead of throwing an error if the read string was invalid.net.minecraft.util.Identifier
readIdentifierSafe()
Reads in a string, and tries to parse it as anIdentifier
.void
readMarker(java.lang.String id)
Reads a "marker" for debug purposes.java.lang.String
readString()
Reads a string of up toShort.MAX_VALUE
length.int
readVarInt()
Reads out an integer using a variable number of bytes, assuming it was written bywriteVarInt(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.NetByteBuf
resetReaderIndex()
NetByteBuf
resetReaderIndex(NetByteBuf.SavedReaderIndex index)
NetByteBuf.SavedReaderIndex
saveReaderIndex()
NetByteBuf
writeBlockPos(net.minecraft.util.math.BlockPos pos)
NetByteBuf
writeBoolean(boolean flag)
Writes a single boolean out to some position in this buffer.NetByteBuf
writeEnumConstant(java.lang.Enum<?> value)
NetByteBuf
writeFixedBits(int value, int length)
Writes a fixed number of bits out to the stream.NetByteBuf
writeIdentifier(net.minecraft.util.Identifier id)
void
writeMarker(java.lang.String id)
Writes a "marker" for debug purposes.NetByteBuf
writeVarInt(int ival)
Writes out an integer using a variable number of bytes.NetByteBuf
writeVarLong(long lval)
Writes out a long integer using a variable number of bytes.NetByteBuf
writeVarUnsignedInt(int ival)
Exposes the vanilla method for writing out an unsigned integer using a variable number of bytes.NetByteBuf
writeVarUnsignedLong(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
NetByteBuf
fromUnpooled.buffer()
-
buffer
- Returns:
- A new
NetByteBuf
fromUnpooled.buffer(int)
-
asNetByteBuf
Returns the givenByteBuf
asNetByteBuf
. if the given instance is already aNetByteBuf
then 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:
copy
in classnet.minecraft.network.PacketByteBuf
-
readBytes
- Overrides:
readBytes
in classnet.minecraft.network.PacketByteBuf
-
clear
- Overrides:
clear
in classnet.minecraft.network.PacketByteBuf
-
markReaderIndex
- Overrides:
markReaderIndex
in classnet.minecraft.network.PacketByteBuf
-
resetReaderIndex
- Overrides:
resetReaderIndex
in 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:
writeBoolean
in 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:
readBoolean
in 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:
writeEnumConstant
in classnet.minecraft.network.PacketByteBuf
-
readEnumConstant
public <E extends java.lang.Enum<E>> E readEnumConstant(java.lang.Class<E> enumClass)- Overrides:
readEnumConstant
in classnet.minecraft.network.PacketByteBuf
-
writeBlockPos
- Overrides:
writeBlockPos
in classnet.minecraft.network.PacketByteBuf
-
readBlockPos
public net.minecraft.util.math.BlockPos readBlockPos()- Overrides:
readBlockPos
in classnet.minecraft.network.PacketByteBuf
-
writeVarInt
Writes out an integer using a variable number of bytes.- 1 byte for
MIN_VAR_S_INT_1_BYTE
toMAX_VAR_S_INT_1_BYTE
- 2 bytes for
MIN_VAR_S_INT_2_BYTES
toMAX_VAR_S_INT_2_BYTES
- 3 bytes for
MIN_VAR_S_INT_3_BYTES
toMAX_VAR_S_INT_3_BYTES
- 4 bytes for
MIN_VAR_S_INT_4_BYTES
toMAX_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 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:
readVarInt
in 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_SMALL
toMAX_VAR_S_INT_1_BYTE
- 2 bytes for
MIN_VAR_U_INT_SMALL
toMAX_VAR_S_INT_2_BYTES
- 3 bytes for
MIN_VAR_U_INT_SMALL
toMAX_VAR_S_INT_3_BYTES
- 4 bytes for
MIN_VAR_U_INT_SMALL
toMAX_VAR_S_INT_4_BYTES
- 5 bytes for
Integer.MIN_VALUE
toInteger.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:
writeVarLong
in classnet.minecraft.network.PacketByteBuf
-
readVarLong
public long readVarLong()- Overrides:
readVarLong
in 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:
writeIdentifier
in classnet.minecraft.network.PacketByteBuf
-
readIdentifier
@Deprecated public net.minecraft.util.Identifier readIdentifier()Deprecated.BecausePacketByteBuf.readIdentifier()
can throw anInvalidIdentifierException
, but- Overrides:
readIdentifier
in 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 thenInvalidInputDataException
is 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_VALUE
length.NOTE: This is just
PacketByteBuf.readString()
but available on the server as well.- Overrides:
readString
in 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
-