Class TagReader
Namespace: Void.Minecraft.Nbt
Assembly: Void.Minecraft.dll
Provides methods for reading NBT data from a stream.
public class TagReader : TagIO, IDisposableInheritance
Derived
Implements
Inherited Members
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()
Constructors
TagReader(Stream, FormatOptions, bool)
Creates a new instance of the stream.
public TagReader(Stream stream, FormatOptions options, bool leaveOpen = false)Parameters
stream Stream
A
options FormatOptions
Bitwise flags to configure how data should be handled for compatibility between different specifications.
leaveOpen bool
to leave the stream object open after disposing the
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public override void Dispose()DisposeAsync()
Asynchronously releases the unmanaged resources used by the
public override ValueTask DisposeAsync()Returns
OnTagEncountered(TagType, bool)
Invokes the
protected virtual Tag? OnTagEncountered(TagType type, bool named)Parameters
type TagType
The type of tag next to be read from the stream.
named bool
Flag indicating if this tag is named.
Returns
Tag?
When handled by an event subscriber, returns a parsed
OnTagRead(Tag)
Invokes the
protected virtual void OnTagRead(Tag tag)Parameters
tag Tag
The deserialized
ReadByte(bool)
Reads a
public ByteTag ReadByte(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadByteArray(bool)
Reads a
public ByteArrayTag ReadByteArray(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadCompound(bool)
Reads a
public CompoundTag ReadCompound(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadDouble(bool)
Reads a
public DoubleTag ReadDouble(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadFloat(bool)
Reads a
public FloatTag ReadFloat(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadInt(bool)
Reads a
public IntTag ReadInt(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadIntArray(bool)
Reads a
public IntArrayTag ReadIntArray(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadList(bool)
Reads a
public ListTag ReadList(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadLong(bool)
Reads a
public LongTag ReadLong(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadLongArray(bool)
Reads a
public LongArrayTag ReadLongArray(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadShort(bool)
Reads a
public ShortTag ReadShort(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadString(bool)
Reads a
public StringTag ReadString(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The deserialized
Remarks
It is assumed that the stream is positioned at the beginning of the tag payload.
ReadTag(bool)
Reads a
public Tag ReadTag(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The tag instance that was read from the stream.
ReadTag<T>(bool)
Convenience method to read a tag and cast it automatically.
public T ReadTag<T>(bool named = true) where T : TagParameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
T
The tag instance that was read from the stream.
Type Parameters
T
The tag type that is being read from the stream.
Remarks
This is typically only used when reading the top-level
ReadTagAsync(bool)
Asynchronously reads a
public Task<Tag> ReadTagAsync(bool named = true)Parameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
The tag instance that was read from the stream.
ReadTagAsync<T>(bool)
Convenience method to asynchronously read a tag and cast it automatically.
public Task<T> ReadTagAsync<T>(bool named = true) where T : TagParameters
named bool
Flag indicating if this tag is named, only false when a tag is a direct child of a
Returns
Task<T>
The tag instance that was read from the stream.
Type Parameters
T
The tag type that is being read from the stream.
Remarks
This is typically only used when reading the top-level
ReadToFixSizedBuffer(Span<byte>)
Reads bytes from the streams and stores them into the buffer.
The number of read bytes is dictated by the size of the buffer.
This method ensures that all requested bytes are read.
protected void ReadToFixSizedBuffer(Span<byte> buffer)Parameters
The buffer where the read bytes are written to. the buffer size defines the number of bytes to read.
Remarks
Use this instead of BaseStream.Read(buffer).
There was a breaking change in .NET 6 where the
Exceptions
Throws if no more bytes could be read from the stream, but the buffer wasn’t completely filled yet.
ReadToFixSizedBuffer(byte[], int, int)
Reads bytes from the streams and stores them into the buffer.
This method ensures that all requested bytes are read.
protected void ReadToFixSizedBuffer(byte[] buffer, int offset, int count)Parameters
buffer byte[]
The buffer where the read bytes are written to. The data will be stored starting at offset to offset + count - 1.
offset int
The offset in buffer where the read data is stored.
count int
The number of bytes to read. Must be positive.
Remarks
Use this instead of BaseStream.Read(buffer, offset, count).
There was a breaking change in .NET 6 where the
Exceptions
Throws if no more bytes could be read from the stream, but the buffer wasn’t completely filled yet.
ReadUTF8String()
Reads a length-prefixed UTF-8 string from the stream.
protected string? ReadUTF8String()Returns
The deserialized string instance.
TagEncountered
Occurs when a tag has been encountered in the stream, after reading the first byte to determine its
public event TagReaderCallback<TagHandledEventArgs>? TagEncounteredEvent Type
TagReaderCallback<TagHandledEventArgs>?
TagRead
Occurs when a tag has been fully deserialized from the stream.
public event TagReaderCallback<TagEventArgs>? TagRead