Skip to content

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 VarInt

Inheritance

objectVarInt

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

long

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

long

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

int

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

int

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 instance to read from.

zigzag bool

Flag indicating if the value is ZigZag encoded.

Returns

int

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 instance to read from.

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

int

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 instance to write the value to.

value int

The value to encode and write.

zigzag bool

Flag indicating if the value will be ZigZag encoded.

Returns

int

The number of bytes written to the stream.