Skip to main content

NbtBufferWriter

static class

Provides methods that write NBT data to an IBufferWriter<T>.

Declaration​

public static class NbtBufferWriter
NamespaceMcProtoNet.NBT
AssemblyMcProtoNet.NBT.dll
Sourcesrc/McProtoNet.NBT/NbtBufferWriter.cs#L16 ↗

Remarks​

The output is Java Edition NBT only: every number is big-endian and every string is modified UTF-8. Nesting is limited to NbtBufferWriter.MaxDepth levels. NbtSpanReader is the counterpart on the reading side.

Fields​

SignatureDescription
const int MaxDepth = 512The maximum nesting depth the writer accepts, which matches the vanilla limit.

MaxDepth​

public const int MaxDepth = 512

The maximum nesting depth the writer accepts, which matches the vanilla limit.

Returns: int

Methods​

SignatureDescription
static void WritePayload<TWriter>(TWriter writer, NbtTag tag) where TWriter : IBufferWriter<byte>Writes only a tag's payload, without the type byte and without the name.
static void WriteString<TWriter>(TWriter writer, scoped ReadOnlySpan<char> value) where TWriter : IBufferWriter<byte>Writes an NBT string: an unsigned big-endian 16-bit byte count, then the modified UTF-8 bytes.
static void WriteTag<TWriter>(TWriter writer, NbtTag tag, bool writeRootName = false) where TWriter : IBufferWriter<byte>Writes a complete tag: the type byte, the root name when requested, then the payload.

WritePayload<TWriter>(TWriter, NbtTag)​

public static void WritePayload<TWriter>(TWriter writer, NbtTag tag) where TWriter : IBufferWriter<byte>

Writes only a tag's payload, without the type byte and without the name.

Parameters: writer (TWriter), tag (NbtTag)

Exceptions: ArgumentNullException - tag is null.; NbtFormatException - The tag is malformed, nested too deeply, holds a string longer than 65535 bytes when encoded, or holds an array whose encoded length does not fit in an int.

WriteString<TWriter>(TWriter, scoped ReadOnlySpan<char>)​

public static void WriteString<TWriter>(TWriter writer, scoped ReadOnlySpan<char> value) where TWriter : IBufferWriter<byte>

Writes an NBT string: an unsigned big-endian 16-bit byte count, then the modified UTF-8 bytes.

Parameters: writer (TWriter), value (ReadOnlySpan<char>)

Exceptions: ArgumentOutOfRangeException - The encoded form of value does not fit in an int.; NbtFormatException - The encoded text is longer than 65535 bytes.

WriteTag<TWriter>(TWriter, NbtTag, bool)​

public static void WriteTag<TWriter>(TWriter writer, NbtTag tag, bool writeRootName = false) where TWriter : IBufferWriter<byte>

Writes a complete tag: the type byte, the root name when requested, then the payload.

Parameters: writer (TWriter), tag (NbtTag), writeRootName (bool)

Exceptions: ArgumentNullException - tag is null.; NbtFormatException - The tag is malformed, nested too deeply, holds a string longer than 65535 bytes when encoded, or holds an array whose encoded length does not fit in an int.