Class NetByteBuf
- All Implemented Interfaces:
io.netty.util.ReferenceCounted
,Comparable<io.netty.buffer.ByteBuf>
- Direct Known Subclasses:
CheckingNetByteBuf
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
-
Field Summary
Modifier and TypeFieldDescriptionstatic NetByteBuf
static int
static int
static int
static int
static int
static int
static int
static int
static int
static int
static int
static int
static int
Fields inherited from class net.minecraft.network.PacketByteBuf
DEFAULT_MAX_STRING_LENGTH, MAX_TEXT_LENGTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic NetByteBuf
asNetByteBuf(io.netty.buffer.ByteBuf buf)
Returns the givenByteBuf
asNetByteBuf
.static NetByteBuf
buffer()
static NetByteBuf
buffer(int initialCapacity)
clear()
copy()
int
Bit version ofPacketByteBuf.readerIndex()
.int
Bit version ofPacketByteBuf.writerIndex()
.boolean
net.minecraft.util.math.BlockPos
boolean
Reads a single boolean from some position in this buffer.readBytes(int length)
<E extends Enum<E>>
EreadEnumConstant(Class<E> enumClass)
int
readFixedBits(int length)
net.minecraft.util.Identifier
Deprecated.net.minecraft.util.Identifier
LikereadIdentifierSafe()
, but returns null instead of throwing an error if the read string was invalid.net.minecraft.util.Identifier
Reads in a string, and tries to parse it as anIdentifier
.void
readMarker(String id)
Reads a "marker" for debug purposes.Reads a string of up toShort.MAX_VALUE
length.int
Reads out an integer using a variable number of bytes, assuming it was written bywriteVarInt(int)
long
int
Exposes the vanilla method for reading an unsigned integer using a variable number of bytes.long
Exposes the vanilla method for reading an unsigned long integer using a variable number of bytes.writeBlockPos(net.minecraft.util.math.BlockPos pos)
writeBoolean(boolean flag)
Writes a single boolean out to some position in this buffer.writeEnumConstant(Enum<?> value)
writeFixedBits(int value, int length)
Writes a fixed number of bits out to the stream.writeIdentifier(net.minecraft.util.Identifier id)
void
writeMarker(String id)
Writes a "marker" for debug purposes.writeVarInt(int ival)
Writes out an integer using a variable number of bytes.writeVarLong(long lval)
Writes out a long integer using a variable number of bytes.writeVarUnsignedInt(int ival)
Exposes the vanilla method for writing out an unsigned integer using a variable number of bytes.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, forEachInCollection, 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, getVarIntLength, getVarLongLength, getWrittenBytes, hasArray, hashCode, hasMemoryAddress, indexOf, internalNioBuffer, isDirect, isReadable, isReadable, isReadOnly, isWritable, isWritable, markWriterIndex, maxCapacity, maxWritableBytes, memoryAddress, nioBuffer, nioBuffer, nioBufferCount, nioBuffers, nioBuffers, order, order, readableBytes, readBitSet, readBlockHitResult, readByte, readByteArray, readByteArray, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readBytes, readChar, readCharSequence, readChunkPos, readChunkSectionPos, readCollection, readDate, readDouble, readerIndex, readerIndex, readFloat, readInt, readIntArray, readIntArray, readIntLE, readIntList, readItemStack, readList, readLong, readLongArray, readLongArray, readLongArray, readLongLE, readMap, readMap, readMedium, readMediumLE, readNbt, readNbt, readRetainedSlice, readShort, readShortLE, readSlice, readString, readText, readUnlimitedNbt, 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, writeBitSet, writeBlockHitResult, writeByte, writeByteArray, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeBytes, writeChar, writeCharSequence, writeChunkPos, writeChunkSectionPos, writeCollection, writeDate, writeDouble, writeFloat, writeInt, writeIntArray, writeIntLE, writeIntList, writeItemStack, writeLong, writeLongArray, writeLongLE, writeMap, writeMedium, writeMediumLE, writeNbt, writerIndex, writerIndex, writeShort, writeShortLE, writeString, writeString, writeText, writeUuid, writeZero
Methods inherited from class io.netty.buffer.ByteBuf
getDoubleLE, getFloatLE, readDoubleLE, readFloatLE, setDoubleLE, setFloatLE, writeDoubleLE, writeFloatLE
-
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). -
getBitWriterIndex
public int getBitWriterIndex()Bit version ofPacketByteBuf.writerIndex()
. -
getBitReaderIndex
public int getBitReaderIndex()Bit version ofPacketByteBuf.readerIndex()
. -
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:
IllegalArgumentException
- if the length argument was less than 1 or greater than 32.
-
readFixedBits
- 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.
-
writeEnumConstant
- Overrides:
writeEnumConstant
in classnet.minecraft.network.PacketByteBuf
-
readEnumConstant
- 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.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
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
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
-
PacketByteBuf.readIdentifier()
can throw anInvalidIdentifierException
, but