Struct MinecraftBuffer
Namespace: Void.Minecraft.Buffers
Assembly: Void.Minecraft.dll
public ref struct MinecraftBufferInherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Constructors
MinecraftBuffer()
public MinecraftBuffer()MinecraftBuffer(Span<byte>)
public MinecraftBuffer(Span<byte> memory)Parameters
MinecraftBuffer(ReadOnlySpan<byte>)
public MinecraftBuffer(ReadOnlySpan<byte> span)Parameters
span ReadOnlySpan<byte>
MinecraftBuffer(ReadOnlySequence<byte>)
public MinecraftBuffer(ReadOnlySequence<byte> sequence)Parameters
sequence ReadOnlySequence<byte>
MinecraftBuffer(MemoryStream)
public MinecraftBuffer(MemoryStream memoryStream)Parameters
memoryStream MemoryStream
Properties
HasData
public readonly bool HasData { get; }Property Value
Length
public readonly long Length { get; }Property Value
Position
public readonly long Position { get; }Property Value
Methods
CopyAsBufferSpan(bool)
public BufferSpan CopyAsBufferSpan(bool read = false)Parameters
read bool
Returns
Dump()
public string Dump()Returns
DumpBytes()
public ReadOnlySpan<byte> DumpBytes()Returns
DumpHex()
public string DumpHex()Returns
GetVarIntSize(int)
public static int GetVarIntSize(int value)Parameters
value int
Returns
Read(long)
public ReadOnlySpan<byte> Read(long length)Parameters
length long
Returns
ReadBoolean()
public bool ReadBoolean()Returns
ReadComponent(bool)
public Component ReadComponent(bool asNbt = true)Parameters
asNbt bool
Returns
ReadDouble()
public double ReadDouble()Returns
ReadFloat()
public float ReadFloat()Returns
ReadInt()
public int ReadInt()Returns
ReadJsonString()
public JsonNode ReadJsonString()Returns
ReadLong()
public long ReadLong()Returns
ReadProperty()
public Property ReadProperty()Returns
ReadPropertyArray()
public Property[] ReadPropertyArray()Returns
Property[]
ReadShort()
public short ReadShort()Returns
ReadString(int)
Reads a Minecraft protocol string encoded as a VarInt byte length followed by UTF-8 bytes.
public string ReadString(int maxLength = 32767)Parameters
maxLength int
Maximum allowed character count for the decoded string.
Returns
The decoded UTF-8 string. The returned value is never null.
Examples
var text = buffer.ReadString(16);
Remarks
This method validates the decoded character length, not the encoded byte length. If maxLength is less than or equal to 0, length validation is skipped.
The buffer read position advances by the size of the string length prefix and payload bytes.
Exceptions
The length prefix is not a valid Minecraft VarInt value.
The decoded string length exceeds maxLength.
Propagated from the underlying buffer implementation in unsupported scenarios.
See Also
ReadTag(bool)
public NbtTag ReadTag(bool readName = true)Parameters
readName bool
Returns
ReadToEnd()
public ReadOnlySpan<byte> ReadToEnd()Returns
ReadUnsignedByte()
public byte ReadUnsignedByte()Returns
ReadUnsignedShort()
public ushort ReadUnsignedShort()Returns
ReadUuid()
public Uuid ReadUuid()Returns
ReadUuidAsIntArray()
public Uuid ReadUuidAsIntArray()Returns
ReadVarInt()
public int ReadVarInt()Returns
ReadVarLong()
public long ReadVarLong()Returns
ReadVarShort()
public int ReadVarShort()Returns
Reset()
public void Reset()Seek(long)
public void Seek(long offset)Parameters
offset long
Seek(long, SeekOrigin)
public void Seek(long offset, SeekOrigin origin)Parameters
offset long
origin SeekOrigin
Write(scoped ReadOnlySpan<byte>)
public void Write(scoped ReadOnlySpan<byte> data)Parameters
data ReadOnlySpan<byte>
Write(Stream)
public void Write(Stream stream)Parameters
stream Stream
WriteBoolean(bool)
public void WriteBoolean(bool value)Parameters
value bool
WriteComponent(Component, bool, bool)
public void WriteComponent(Component value, bool asNbt = true, bool writeNbtName = false)Parameters
value Component
asNbt bool
writeNbtName bool
WriteDouble(double)
public void WriteDouble(double value)Parameters
value double
WriteFloat(float)
public void WriteFloat(float value)Parameters
value float
WriteInt(int)
public void WriteInt(int value)Parameters
value int
WriteJsonString(JsonNode, JsonSerializerOptions?)
public void WriteJsonString(JsonNode node, JsonSerializerOptions? jsonSerializerOptions = null)Parameters
node JsonNode
jsonSerializerOptions JsonSerializerOptions?
WriteLong(long)
public void WriteLong(long value)Parameters
value long
WriteProperty(Property)
public void WriteProperty(Property value)Parameters
value Property
WritePropertyArray(Property[]?)
Writes a profile property array using Minecraft’s length-prefixed format.
public void WritePropertyArray(Property[]? value)Parameters
value Property[]?
The properties to serialize. When null, an empty array is written.
Examples
buffer.WritePropertyArray(profile.Properties);
Remarks
This method writes a VarInt element count first, then serializes each
Passing null is equivalent to passing [], so the written count is 0.
Exceptions
Propagated from
See Also
MinecraftBuffer.ReadPropertyArray()
WriteShort(short)
public void WriteShort(short value)Parameters
value short
WriteString(ReadOnlySpan<char>)
Writes a Minecraft protocol string as UTF-8 bytes prefixed by its byte length encoded as VarInt.
public void WriteString(ReadOnlySpan<char> value)Parameters
value ReadOnlySpan<char>
The characters to encode and write.
Examples
buffer.WriteString("minecraft:stone");
Remarks
The method writes the UTF-8 byte count first, then writes the encoded bytes. An empty span writes a zero length prefix and no payload bytes.
This method mutates the buffer by advancing the current position and appending or overwriting data depending on the backing storage.
Exceptions
The underlying backing buffer is read-only.
InternalBufferOverflowException
The target writable span does not have enough capacity for the encoded payload.
See Also
MinecraftBuffer.WriteVarInt(int)
WriteTag(NbtTag, bool)
public void WriteTag(NbtTag value, bool writeName = true)Parameters
value NbtTag
writeName bool
WriteUnsignedByte(byte)
public void WriteUnsignedByte(byte value)Parameters
value byte
WriteUnsignedShort(ushort)
public void WriteUnsignedShort(ushort value)Parameters
value ushort
WriteUuid(Uuid)
public void WriteUuid(Uuid value)Parameters
value Uuid
WriteUuidAsIntArray(Uuid)
public void WriteUuidAsIntArray(Uuid value)Parameters
value Uuid
WriteVarInt(int)
public void WriteVarInt(int value)Parameters
value int
WriteVarLong(long)
public void WriteVarLong(long value)Parameters
value long
WriteVarShort(int)
public void WriteVarShort(int value)Parameters
value int