Interface NetworkBuffer
public sealed interface NetworkBuffer
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfacestatic interfacestatic interfaceSelf-contained interface that extendsDataInputandDataOutputfor mostly reading/writing binary tags.static interfaceNetworkBuffer.Type<T extends @UnknownNullability Object> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final NetworkBuffer.Type<BitSet> static final NetworkBuffer.Type<Point> static final NetworkBuffer.Type<Boolean> static final NetworkBuffer.Type<Byte> static final NetworkBuffer.Type<byte[]> static final NetworkBuffer.Type<Component> static final NetworkBuffer.Type<Direction> static final NetworkBuffer.Type<Double> static final NetworkBuffer.Type<Float> static final NetworkBuffer.Type<Instant> static final NetworkBuffer.Type<Integer> static final NetworkBuffer.Type<Component> static final NetworkBuffer.Type<Key> static final NetworkBuffer.Type<Long> static final NetworkBuffer.Type<long[]> static final NetworkBuffer.Type<Vec> static final NetworkBuffer.Type<BinaryTag> static final NetworkBuffer.Type<CompoundBinaryTag> static final NetworkBuffer.Type<@Nullable Point> static final NetworkBuffer.Type<@Nullable Component> static final NetworkBuffer.Type<@Nullable Integer> static final NetworkBuffer.Type<Pos> static final NetworkBuffer.Type<EntityPose> static final NetworkBuffer.Type<PublicKey> static final NetworkBuffer.Type<float[]> static final NetworkBuffer.Type<byte[]> static final NetworkBuffer.Type<Short> static final NetworkBuffer.Type<String> static final NetworkBuffer.Type<String> static final NetworkBuffer.Type<String> static final NetworkBuffer.Type<Unit> static final NetworkBuffer.Type<Short> static final NetworkBuffer.Type<Long> static final NetworkBuffer.Type<Integer> static final NetworkBuffer.Type<UUID> static final NetworkBuffer.Type<Integer> static final NetworkBuffer.Type<Integer> static final NetworkBuffer.Type<int[]> static final NetworkBuffer.Type<Long> static final NetworkBuffer.Type<long[]> static final NetworkBuffer.Type<Point> static final NetworkBuffer.Type<Point> static final NetworkBuffer.Type<Point> static final NetworkBuffer.Type<Point> -
Method Summary
Modifier and TypeMethodDescriptionlongadvanceRead(long length) longadvanceWrite(long length) static NetworkBuffer.Builderbuilder(long size) longcapacity()voidclear()voidcompact()longcompress(long start, long length, NetworkBuffer output) default NetworkBuffercopy(long index, long length) copy(long index, long length, long readIndex, long writeIndex) static voidcopy(NetworkBuffer srcBuffer, long srcOffset, NetworkBuffer dstBuffer, long dstOffset, long length) voidcopyTo(long srcOffset, byte[] dest, int destOffset, int length) voidcopyTo(long srcOffset, MemorySegment dest, long destOffset, long length) longdecompress(long start, long length, NetworkBuffer output) static <L,R> NetworkBuffer.Type <Either<L, R>> Either(NetworkBuffer.Type<L> left, NetworkBuffer.Type<R> right) voidensureReadable(long length) voidensureWritable(long length) static <E extends Enum<E>>
NetworkBuffer.Type<E> static <E extends Enum<E>>
NetworkBuffer.Type<EnumSet<E>> static booleanequals(NetworkBuffer buffer1, NetworkBuffer buffer2) byte[]extractBytes(Consumer<NetworkBuffer> extractor) static NetworkBuffer.Type<BitSet> FixedBitSet(int length) static NetworkBuffer.Type<byte[]> FixedRawBytes(int length) index(long readIndex, long writeIndex) ioView()Creates a newNetworkBuffer.IOViewof this buffer.booleanstatic <T> NetworkBuffer.Type<T> Lazy(Supplier<NetworkBuffer.Type<T>> supplier) static byte[]makeArray(Consumer<NetworkBuffer> writing) static byte[]makeArray(Consumer<NetworkBuffer> writing, @Nullable Registries registries) static <T> byte[]makeArray(NetworkBuffer.Type<T> type, T value) static <T> byte[]makeArray(NetworkBuffer.Type<T> type, T value, @Nullable Registries registries) <T extends @UnknownNullability Object>
Tread(NetworkBuffer.Type<T> type) long<T extends @UnknownNullability Object>
TreadAt(long index, NetworkBuffer.Type<T> type) intreadChannel(ReadableByteChannel channel) longreadIndex(long readIndex) readOnly()static <T> NetworkBuffer.Type<T> Recursive(Function<NetworkBuffer.Type<T>, NetworkBuffer.Type<T>> func) voidregistries(@Nullable Registries registries) static NetworkBufferstatic NetworkBufferresizableBuffer(int initialSize) static NetworkBufferresizableBuffer(long initialSize, Registries registries) static NetworkBufferresizableBuffer(Registries registries) voidresize(long newSize) slice(long offset, long byteLength, long readIndex, long writeIndex) A slice is an operation where the backing memory is used for the new buffer.static NetworkBufferstaticBuffer(long size) static NetworkBufferstaticBuffer(long size, Registries registries) static <T,D> NetworkBuffer.Type <T> Tagged(NetworkBuffer.Type<D> discriminator, Function<? super T, ? extends D> discriminatorFromValue, Map<? super D, ? extends NetworkBuffer.Type<? extends T>> serializerMap) static <T,D> NetworkBuffer.Type <T> Tagged(NetworkBuffer.Type<D> discriminator, Function<? super T, ? extends D> discriminatorFromValue, Map<? super D, ? extends NetworkBuffer.Type<? extends T>> serializerMap, @Nullable NetworkBuffer.Type<? extends T> fallback) static <T> NetworkBuffer.Type<T> static NetworkBufferwrap(byte[] bytes, int readIndex, int writeIndex) static NetworkBufferwrap(byte[] bytes, int readIndex, int writeIndex, @Nullable Registries registries) static NetworkBufferwrap(MemorySegment segment, long readIndex, long writeIndex) static NetworkBufferwrap(MemorySegment segment, long readIndex, long writeIndex, @Nullable Registries registries) long<T extends @UnknownNullability Object>
voidwrite(NetworkBuffer.Type<T> type, T value) <T extends @UnknownNullability Object>
voidwriteAt(long index, NetworkBuffer.Type<T> type, T value) booleanwriteChannel(WritableByteChannel channel) longwriteIndex(long writeIndex)
-
Field Details
-
UNIT
-
BOOLEAN
-
BYTE
-
UNSIGNED_BYTE
-
SHORT
-
UNSIGNED_SHORT
-
INT
-
UNSIGNED_INT
-
LONG
-
FLOAT
-
DOUBLE
-
VAR_INT
-
OPTIONAL_VAR_INT
-
VAR_INT_3
-
VAR_LONG
-
RAW_BYTES
-
STRING
-
KEY
-
STRING_TERMINATED
-
STRING_IO_UTF8
-
NBT
-
NBT_COMPOUND
-
BLOCK_POSITION
-
COMPONENT
-
JSON_COMPONENT
-
UUID
-
POS
-
BYTE_ARRAY
-
LONG_ARRAY
-
VAR_INT_ARRAY
-
VAR_LONG_ARRAY
-
BITSET
-
INSTANT_MS
-
PUBLIC_KEY
-
VECTOR3
-
VECTOR3D
-
VECTOR3I
-
VECTOR3B
-
LP_VECTOR3
-
QUATERNION
-
OPT_CHAT
-
OPT_BLOCK_POSITION
-
DIRECTION
-
POSE
-
-
Method Details
-
Enum
-
EnumSet
-
FixedBitSet
-
FixedRawBytes
-
Lazy
-
TypedNBT
-
Either
static <L,R> NetworkBuffer.Type<Either<L,R>> Either(NetworkBuffer.Type<L> left, NetworkBuffer.Type<R> right) -
Recursive
static <T> NetworkBuffer.Type<T> Recursive(Function<NetworkBuffer.Type<T>, NetworkBuffer.Type<T>> func) -
Tagged
static <T,D> NetworkBuffer.Type<T> Tagged(NetworkBuffer.Type<D> discriminator, Function<? super T, ? extends D> discriminatorFromValue, Map<? super D, ? extends NetworkBuffer.Type<? extends T>> serializerMap, @Nullable @Nullable NetworkBuffer.Type<? extends T> fallback) -
Tagged
static <T,D> NetworkBuffer.Type<T> Tagged(NetworkBuffer.Type<D> discriminator, Function<? super T, ? extends D> discriminatorFromValue, Map<? super D, ? extends NetworkBuffer.Type<? extends T>> serializerMap) -
write
<T extends @UnknownNullability Object> void write(NetworkBuffer.Type<T> type, T value) throws IndexOutOfBoundsException - Throws:
IndexOutOfBoundsException
-
read
<T extends @UnknownNullability Object> T read(NetworkBuffer.Type<T> type) throws IndexOutOfBoundsException - Throws:
IndexOutOfBoundsException
-
writeAt
<T extends @UnknownNullability Object> void writeAt(long index, NetworkBuffer.Type<T> type, T value) throws IndexOutOfBoundsException - Throws:
IndexOutOfBoundsException
-
readAt
<T extends @UnknownNullability Object> T readAt(long index, NetworkBuffer.Type<T> type) throws IndexOutOfBoundsException - Throws:
IndexOutOfBoundsException
-
copyTo
void copyTo(long srcOffset, byte[] dest, int destOffset, int length) -
copyTo
-
extractBytes
-
clear
NetworkBuffer clear() -
writeIndex
long writeIndex() -
readIndex
long readIndex() -
writeIndex
-
readIndex
-
index
-
advanceWrite
long advanceWrite(long length) -
advanceRead
long advanceRead(long length) -
readableBytes
long readableBytes() -
writableBytes
long writableBytes() -
capacity
long capacity() -
readOnly
-
isReadOnly
boolean isReadOnly() -
resize
void resize(long newSize) -
ensureWritable
- Throws:
IndexOutOfBoundsException
-
ensureReadable
- Throws:
IndexOutOfBoundsException
-
compact
void compact() -
copy
-
copy
-
readChannel
- Throws:
IOException
-
writeChannel
- Throws:
IOException
-
cipher
-
compress
-
decompress
- Throws:
DataFormatException
-
registries
-
registries
-
slice
@Contract(pure=true, value="_, _, _, _ -> new") NetworkBuffer slice(long offset, long byteLength, long readIndex, long writeIndex) A slice is an operation where the backing memory is used for the new buffer. Consider it a view over the backing memory region.- Parameters:
offset- the position to start the slicebyteLength- the length of the slice, equal tocapacity()readIndex- the read indexwriteIndex- the write index- Returns:
- a new buffer
- Throws:
IllegalArgumentException- if this buffer is a dummy- API Note:
- With resized segments, you could observe behavior where you may see stale data or close arenas.
To avoid this, do not use resizable segments in a way where they are written or resized like
resize(long). - Implementation Note:
registries()are copied into the new buffer
-
ioView
Creates a newNetworkBuffer.IOViewof this buffer.
Useful to interface with API's that supportDataInputorDataOutput.- Returns:
- the io view.
-
builder
-
staticBuffer
-
staticBuffer
-
resizableBuffer
-
resizableBuffer
-
resizableBuffer
-
resizableBuffer
-
wrap
static NetworkBuffer wrap(MemorySegment segment, long readIndex, long writeIndex, @Nullable @Nullable Registries registries) -
wrap
-
wrap
static NetworkBuffer wrap(byte[] bytes, int readIndex, int writeIndex, @Nullable @Nullable Registries registries) -
wrap
-
makeArray
-
makeArray
-
makeArray
static <T> byte[] makeArray(NetworkBuffer.Type<T> type, T value, @Nullable @Nullable Registries registries) -
makeArray
-
copy
static void copy(NetworkBuffer srcBuffer, long srcOffset, NetworkBuffer dstBuffer, long dstOffset, long length) -
equals
-