Skip to content

Class VarLong

Namespace: Void.Minecraft.Nbt
Assembly: Void.Minecraft.dll

Provides static methods for reading and writing variable-length integers that are up to 10 bytes from both streams and buffers.

public static class VarLong

Inheritance

objectVarLong

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 10 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 10 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 10 bytes long.

public static long 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

long

The decoded value.

Decode(ReadOnlySpan<byte>, bool)

Decodes a buffer of bytes that represent a variable-length integer up to 10 bytes long.

public static long 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

long

The decoded value.

Encode(long, bool)

Encodes the given value and returns an array of bytes that represent it.

public static byte[] Encode(long value, bool zigzag = false)

Parameters

value long

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 10 bytes from the given stream and returns the VarLong value as a 64-bit integer.

public static long 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

long

The parsed value read from the stream.

Read(Stream, out int, bool)

Reads up to 10 bytes from the given stream and returns the VarLong value as a 64-bit integer.

public static long 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

long

The parsed value read from the stream.

Write(Stream, long, bool)

Encodes the given value to a variable-length integer up to 10 bytes long, and writes it to the stream.

public static int Write(Stream stream, long value, bool zigzag = false)

Parameters

stream Stream

A instance to write the value to.

value long

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.