Contents
Class VarInt
java.lang.Object
com.hypixel.hytale.protocol.io.VarInt
Static helpers for VarInt encoding/decoding.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intget(MemorySegment mem, int offset) static longgetWithLength(MemorySegment mem, int offset) Read a varint value and its encoded byte length in a single pass.static intlength(io.netty.buffer.ByteBuf buf, int index) Get varint byte length at index.static intlength(MemorySegment mem, int offset) static intpeek(io.netty.buffer.ByteBuf buf, int index) Peek varint at absolute index without moving reader.static intread(io.netty.buffer.ByteBuf buf) Read a varint from the buffer, advancing the reader index.static intset(MemorySegment mem, int offset, int value) static intsize(int value) Compute the number of bytes required to encode a varint value.static voidwrite(io.netty.buffer.ByteBuf buf, int value) Write a varint to the buffer.
-
Method Details
-
write
public static void write(@Nonnull io.netty.buffer.ByteBuf buf, int value) Write a varint to the buffer.- Throws:
IllegalArgumentException- if value is negative
-
read
public static int read(@Nonnull io.netty.buffer.ByteBuf buf) Read a varint from the buffer, advancing the reader index.- Throws:
ProtocolException- if the varint encoding exceeds 5 bytes
-
peek
public static int peek(@Nonnull io.netty.buffer.ByteBuf buf, int index) Peek varint at absolute index without moving reader.- Returns:
- the varint value, or -1 if invalid/incomplete
-
length
public static int length(@Nonnull io.netty.buffer.ByteBuf buf, int index) Get varint byte length at index.- Returns:
- the byte length, or -1 if invalid
-
length
-
set
-
get
-
getWithLength
Read a varint value and its encoded byte length in a single pass. Returns a packed long: lower 32 bits = varint value, bits 32-34 = byte length (1-5). Returns -1L if the varint is invalid or incomplete.Extract with:
int value = (int) packed;andint length = (int) (packed >>> 32); -
size
public static int size(int value) Compute the number of bytes required to encode a varint value.
-