Class VarInt
Namespace: Void.Minecraft.Nbt
Assembly: Void.Minecraft.dll
Provides static methods for reading and writing variable-length integers that are up to 5 bytes from both streams and buffers.
public static class VarIntInheritance
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Methods
Decode(byte[], int, int, out int, bool)
Decodes a buffer of bytes that represent a variable-length integer up to 5 bytes long.
public static long Decode(byte[] buffer, int offset, int count, out int size, bool zigzag = false)Parameters
buffer byte[]
A buffer containing the data to be decoded.
offset int
The offset into the buffer to begin reading.
count int
The maximum number of bytes that should be read from the buffer.
size int
A variable to store the actual number of bytes read from the buffer.
zigzag bool
Flag indicating if the value is ZigZag encoded.
Returns
The decoded value.
Decode(byte[], int, int, bool)
Decodes a buffer of bytes that represent a variable-length integer up to 5 bytes long.
public static long Decode(byte[] buffer, int offset, int count, bool zigzag = false)Parameters
buffer byte[]
A buffer containing the data to be decoded.
offset int
The offset into the buffer to begin reading.
count int
The maximum number of bytes that should be read from the buffer.
zigzag bool
Flag indicating if the value is ZigZag encoded.
Returns
The decoded value.
Decode(ReadOnlySpan<byte>, out int, bool)
Decodes a buffer of bytes that represent a variable-length integer up to 5 bytes long.
public static int Decode(ReadOnlySpan<byte> buffer, out int size, bool zigzag = false)Parameters
buffer ReadOnlySpan<byte>
A buffer containing the data to be decoded.
size int
A variable to store the actual number of bytes read from the buffer.
zigzag bool
Flag indicating if the value is ZigZag encoded.
Returns
The decoded value.
Decode(ReadOnlySpan<byte>, bool)
Decodes a buffer of bytes that represent a variable-length integer up to 5 bytes long.
public static int Decode(ReadOnlySpan<byte> buffer, bool zigzag = false)Parameters
buffer ReadOnlySpan<byte>
A buffer containing the data to be decoded.
zigzag bool
Flag indicating if the value is ZigZag encoded.
Returns
The decoded value.
Encode(int, bool)
Encodes the given value and returns an array of bytes that represent it.
public static byte[] Encode(int value, bool zigzag = false)Parameters
value int
The value to encode.
zigzag bool
Flag indicating if the value will be ZigZag encoded.
Returns
byte[]
An array of bytes representing the value as a variable length integer.
Read(Stream, bool)
Reads up to 5 bytes from the given stream and returns the VarInt value as a 32-bit integer.
public static int Read(Stream stream, bool zigzag = false)Parameters
stream Stream
A
zigzag bool
Flag indicating if the value is ZigZag encoded.
Returns
The parsed value read from the stream.
Read(Stream, out int, bool)
Reads up to 5 bytes from the given stream and returns the VarInt value as a 32-bit integer.
public static int Read(Stream stream, out int size, bool zigzag = false)Parameters
stream Stream
A
size int
A variable to store the number of bytes read from the stream.
zigzag bool
Flag indicating if the value is ZigZag encoded.
Returns
The parsed value read from the stream.
Write(Stream, int, bool)
Encodes the given value to a variable-length integer up to 5 bytes long, and writes it to the stream.
public static int Write(Stream stream, int value, bool zigzag = false)Parameters
stream Stream
A
value int
The value to encode and write.
zigzag bool
Flag indicating if the value will be ZigZag encoded.
Returns
The number of bytes written to the stream.