Skip to content

Class BufferedTagWriter

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

Provides a object that writes to an internal buffer instead of a object, which then can be retrieved as an array of bytes or written directly to a stream. This is especially convenient when creating packets to be sent over a network, where the size of the packet must be pre-determined before sending.

public class BufferedTagWriter : TagWriter, IDisposable

Inheritance

objectTagIOTagWriterBufferedTagWriter

Implements

IDisposable

Inherited Members

TagWriter.WriteByte(ByteTag), TagWriter.WriteShort(ShortTag), TagWriter.WriteInt(IntTag), TagWriter.WriteLong(LongTag), TagWriter.WriteFloat(FloatTag), TagWriter.WriteDouble(DoubleTag), TagWriter.WriteString(StringTag), TagWriter.WriteByteArray(ByteArrayTag), TagWriter.WriteIntArray(IntArrayTag), TagWriter.WriteLongArray(LongArrayTag), TagWriter.WriteList(ListTag), TagWriter.WriteCompound(CompoundTag), TagWriter.WriteBuilder(TagBuilder), TagWriter.WriteEndTag(EndTag?), TagWriter.WriteTag(Tag), TagWriter.WriteTagAsync(Tag), TagWriter.Dispose(), TagWriter.DisposeAsync(), TagIO.BaseStream, TagIO.SwapEndian, TagIO.UseVarInt, TagIO.ZigZagEncoding, TagIO.FormatOptions, TagIO.Dispose(), TagIO.DisposeAsync(), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Properties

Capacity

Gets the capacity of the internal buffer.

public long Capacity { get; }

Property Value

long

Remarks

The capacity will expand automatically as-needed.

Length

Gets the number of bytes in the internal buffer.

public long Length { get; }

Property Value

long

Methods

CopyTo(Stream)

Copies the internal buffer to the specified stream;

public void CopyTo(Stream stream)

Parameters

stream Stream

A instance to write to.

CopyToAsync(Stream)

Asynchronously copies the internal buffer to the specified stream;

public Task CopyToAsync(Stream stream)

Parameters

stream Stream

A instance to write to.

Returns

Task

Create(CompressionType, FormatOptions)

Creates a new instance of the class.

public static BufferedTagWriter Create(CompressionType compression, FormatOptions options)

Parameters

compression CompressionType

Indicates the compression algorithm used to compress the file.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

Returns

BufferedTagWriter

A newly created instance.

Exceptions

ArgumentOutOfRangeException

Thrown when an invalid compression type is specified.

Create(CompressionType, FormatOptions, int)

Creates a new instance of the class.

public static BufferedTagWriter Create(CompressionType compression, FormatOptions options, int capacity)

Parameters

compression CompressionType

Indicates the compression algorithm used to compress the file.

options FormatOptions

Bitwise flags to configure how data should be handled for compatibility between different specifications.

capacity int

The initial capacity of the buffer.

Returns

BufferedTagWriter

A newly created instance.

Exceptions

ArgumentOutOfRangeException

Thrown when an invalid compression type is specified.

ToArray()

Gets the internal buffer as an array of bytes containing the NBT data written so far.

public byte[] ToArray()

Returns

byte[]

An array of bytes containing the NBT data.

Operators

implicit operator ReadOnlySpan<byte>(BufferedTagWriter)

Implicit conversion of to a .

public static implicit operator ReadOnlySpan<byte>(BufferedTagWriter writer)

Parameters

writer BufferedTagWriter

Returns

ReadOnlySpan<byte>