Class FriendlyByteBuffer

java.lang.Object
dev.jorel.commandapi.network.FriendlyByteBuffer

public class FriendlyByteBuffer extends Object
A sequence of bytes that can be written to and read from.

Reading and writing is handled by two ints, the readIndex and writeIndex, which can be accessed using getReadIndex() and getWriteIndex() respectively. These indices are automatically incremented when reading and writing bytes. If the readIndex is ever greater than or equal to the writeIndex when a byte is read, an IllegalStateException will be thrown for attempting to read out of bounds.

This class provides methods that make it easier to read and write certain data types, using methods like readVarInt() and writeVarInt(int). These methods handle formatting the bytes correctly, letting developers simply worry about the structure of their data. If a specific method has a problem while reading bytes, an appropriate IllegalStateException will be thrown to indicate something is misformatted.

This buffer can be created empty (FriendlyByteBuffer()), or pre-written with a byte array (FriendlyByteBuffer(byte[])).