public void Serialize(MinecraftStream minecraftStream) { using var stream = new MinecraftStream(); using var dataStream = new MinecraftStream(); stream.WriteInt(Chunk.X); stream.WriteInt(Chunk.Z); //Chunk.CalculateHeightmap(); var writer = new NbtWriter(stream, string.Empty); foreach (var(type, heightmap) in Chunk.Heightmaps) { if (type == ChunkData.HeightmapType.MotionBlocking) { writer.WriteTag(new NbtArray <long>(type.ToString().ToSnakeCase().ToUpper(), heightmap.GetDataArray().Cast <long>())); } } writer.EndCompound(); writer.TryFinish(); foreach (var section in Chunk.Sections) { if (section is { BlockStateContainer.IsEmpty: false })
public Task WriteNbtAsync(NbtTag tag) { var writer = new NbtWriter(new MemoryStream(), "Item"); writer.WriteTag(tag); writer.EndCompound(); writer.Finish(); return(Task.CompletedTask); }
public void WriteMixedCodec(MixedCodec value) { var writer = new NbtWriter(this, ""); var list = new NbtList(NbtTagType.Compound, "value"); foreach (var(_, codec) in value.Dimensions) { codec.Write(list); } var dimensions = new NbtCompound(value.Dimensions.Name) { new NbtTag <string>("type", value.Dimensions.Name), list }; #region biomes var biomes = new NbtList(NbtTagType.Compound, "value"); foreach (var(_, biome) in value.Biomes) { biome.Write(biomes); } var biomeCompound = new NbtCompound(value.Biomes.Name) { new NbtTag <string>("type", value.Biomes.Name), biomes }; #endregion writer.WriteTag(dimensions); writer.WriteTag(biomeCompound); writer.EndCompound(); writer.TryFinish(); }
public void Serialize(MinecraftStream minecraftStream) { using var stream = new MinecraftStream(); using var dataStream = new MinecraftStream(); stream.WriteInt(Chunk.X); stream.WriteInt(Chunk.Z); stream.WriteBoolean(true); // full chunk int chunkSectionY = 0, mask = 0; foreach (var section in Chunk.Sections) { if ((changedSectionFilter & 1 << chunkSectionY) != 0) { mask |= 1 << chunkSectionY; section.WriteTo(dataStream); } chunkSectionY++; } stream.WriteVarInt(mask); Chunk.CalculateHeightmap(); var writer = new NbtWriter(stream, string.Empty); foreach (var(type, heightmap) in Chunk.Heightmaps) { writer.WriteTag(new NbtArray <long>(type.ToString().ToSnakeCase().ToUpper(), heightmap.GetDataArray().Cast <long>())); } writer.EndCompound(); Chunk.BiomeContainer.WriteTo(stream); dataStream.Position = 0; stream.WriteVarInt((int)dataStream.Length); dataStream.CopyTo(stream); stream.WriteVarInt(0); minecraftStream.Lock.Wait(); minecraftStream.WriteVarInt(Id.GetVarIntLength() + (int)stream.Length); minecraftStream.WriteVarInt(Id); stream.Position = 0; stream.CopyTo(minecraftStream); minecraftStream.Lock.Release(); }
static void WriteMetadata([NotNull] Map mapToSave, [NotNull] NbtWriter writer) { writer.BeginCompound("Metadata"); { // write fCraft's native metadata writer.BeginCompound("fCraft"); { string oldEntry = null; foreach (MetadataEntry <string> entry in mapToSave.Metadata) { if (oldEntry != entry.Group) { // TODO: Modify MetadataCollection to allow easy iteration group-at-a-time if (oldEntry != null) { writer.EndCompound(); } oldEntry = entry.Group; writer.BeginCompound(entry.Group); } writer.WriteString(entry.Key, entry.Value); } if (oldEntry != null) { writer.EndCompound(); } } writer.EndCompound(); // TODO: write CPE metadata here // write foreign metadata if (MapUtility.PreserveForeignMetadata && mapToSave.ForeignMetadata != null) { foreach (NbtTag metaGroup in mapToSave.ForeignMetadata) { writer.WriteTag(metaGroup); } } } writer.EndCompound(); }
public void WriteTagTest() { using (var ms = new MemoryStream()) { var writer = new NbtWriter(ms, "root"); { foreach (NbtTag tag in TestFiles.MakeValueTest().Tags) { writer.WriteTag(tag); } writer.EndCompound(); Assert.IsTrue(writer.IsDone); writer.Finish(); } ms.Position = 0; var file = new NbtFile(); long bytesRead = file.LoadFromBuffer(ms.ToArray(), 0, (int)ms.Length, NbtCompression.None); Assert.AreEqual(bytesRead, ms.Length); TestFiles.AssertValueTest(file); } }
public void Write(NbtTag value) { _nbtWriter.WriteTag(value); }
public void WriteTagTest() { using (var ms = new MemoryStream()) { var writer = new NbtWriter(ms, "root"); { foreach (NbtTag tag in TestFiles.MakeValueTest().Tags) { writer.WriteTag(tag); } writer.EndCompound(); writer.Finish(); } ms.Position = 0; var file = new NbtFile(); file.LoadFromBuffer(ms.ToArray(), 0, (int)ms.Length, NbtCompression.None); TestFiles.AssertValueTest(file); } }
public void ErrorTest() { using (var ms = new MemoryStream()) { // null constructor parameters, or a non-writable stream Assert.Throws<ArgumentNullException>(() => new NbtWriter(null, "root")); Assert.Throws<ArgumentNullException>(() => new NbtWriter(ms, null)); Assert.Throws<ArgumentException>(() => new NbtWriter(new NonWritableStream(), "root")); var writer = new NbtWriter(ms, "root"); { // use negative list size Assert.Throws<ArgumentOutOfRangeException>(() => writer.BeginList("list", NbtTagType.Int, -1)); writer.BeginList("listOfLists", NbtTagType.List, 1); Assert.Throws<ArgumentOutOfRangeException>(() => writer.BeginList(NbtTagType.Int, -1)); writer.BeginList(NbtTagType.Int, 0); writer.EndList(); writer.EndList(); writer.BeginList("list", NbtTagType.Int, 1); // invalid list type Assert.Throws<ArgumentOutOfRangeException>(() => writer.BeginList(NbtTagType.End, 0)); // call EndCompound when not in a compound Assert.Throws<NbtFormatException>(writer.EndCompound); // end list before all elements have been written Assert.Throws<NbtFormatException>(writer.EndList); // write the wrong kind of tag inside a list Assert.Throws<NbtFormatException>(() => writer.WriteShort(0)); // write a named tag where an unnamed tag is expected Assert.Throws<NbtFormatException>(() => writer.WriteInt("NamedInt", 0)); // write too many list elements writer.WriteTag(new NbtInt()); Assert.Throws<NbtFormatException>(() => writer.WriteInt(0)); writer.EndList(); // write a null tag Assert.Throws<ArgumentNullException>(() => writer.WriteTag(null)); // write an unnamed tag where a named tag is expected Assert.Throws<NbtFormatException>(() => writer.WriteTag(new NbtInt())); Assert.Throws<NbtFormatException>(() => writer.WriteInt(0)); // end a list when not in a list Assert.Throws<NbtFormatException>(writer.EndList); // write null values where unacceptable Assert.Throws<ArgumentNullException>(() => writer.WriteString("NullString", null)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray("NullByteArray", null)); Assert.Throws<ArgumentNullException>(() => writer.WriteIntArray("NullIntArray", null)); Assert.Throws<ArgumentNullException>(() => writer.WriteString(null)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray(null)); Assert.Throws<ArgumentNullException>(() => writer.WriteIntArray(null)); // trying to read from non-readable stream Assert.Throws<ArgumentException>( () => writer.WriteByteArray("ByteStream", new NonReadableStream(), 0)); // finish too early Assert.Throws<NbtFormatException>(writer.Finish); writer.EndCompound(); writer.Finish(); // write tag after finishing Assert.Throws<NbtFormatException>(() => writer.WriteTag(new NbtInt())); } } }
public void ErrorTest() { byte[] dummyByteArray = { 1, 2, 3, 4, 5 }; int[] dummyIntArray = { 1, 2, 3, 4, 5 }; byte[] dummyBuffer = new byte[1024]; MemoryStream dummyStream = new MemoryStream(dummyByteArray); using (var ms = new MemoryStream()) { // null constructor parameters, or a non-writable stream Assert.Throws <ArgumentNullException>(() => new NbtWriter(null, "root")); Assert.Throws <ArgumentNullException>(() => new NbtWriter(ms, null)); Assert.Throws <ArgumentException>(() => new NbtWriter(new NonWritableStream(), "root")); var writer = new NbtWriter(ms, "root"); { // use negative list size Assert.Throws <ArgumentOutOfRangeException>(() => writer.BeginList("list", NbtTagType.Int, -1)); writer.BeginList("listOfLists", NbtTagType.List, 1); Assert.Throws <ArgumentOutOfRangeException>(() => writer.BeginList(NbtTagType.Int, -1)); writer.BeginList(NbtTagType.Int, 0); writer.EndList(); writer.EndList(); writer.BeginList("list", NbtTagType.Int, 1); // invalid list type Assert.Throws <ArgumentOutOfRangeException>(() => writer.BeginList(NbtTagType.End, 0)); Assert.Throws <ArgumentOutOfRangeException>(() => writer.BeginList("list", NbtTagType.End, 0)); // call EndCompound when not in a compound Assert.Throws <NbtFormatException>(writer.EndCompound); // end list before all elements have been written Assert.Throws <NbtFormatException>(writer.EndList); // write the wrong kind of tag inside a list Assert.Throws <NbtFormatException>(() => writer.WriteShort(0)); // write a named tag where an unnamed tag is expected Assert.Throws <NbtFormatException>(() => writer.WriteInt("NamedInt", 0)); // write too many list elements writer.WriteTag(new NbtInt()); Assert.Throws <NbtFormatException>(() => writer.WriteInt(0)); writer.EndList(); // write a null tag Assert.Throws <ArgumentNullException>(() => writer.WriteTag(null)); // write an unnamed tag where a named tag is expected Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtInt())); Assert.Throws <NbtFormatException>(() => writer.WriteInt(0)); // end a list when not in a list Assert.Throws <NbtFormatException>(writer.EndList); // unacceptable nulls: WriteString Assert.Throws <ArgumentNullException>(() => writer.WriteString(null)); Assert.Throws <ArgumentNullException>(() => writer.WriteString("NullString", null)); // unacceptable nulls: WriteByteArray from array Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray(null)); Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray(null, 0, 5)); Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray("NullByteArray", null)); Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray("NullByteArray", null, 0, 5)); // unacceptable nulls: WriteByteArray from stream Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray(null, 5)); Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray(null, 5, null)); Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray(dummyStream, 5, null)); Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray("NullBuffer", dummyStream, 5, null)); Assert.Throws <ArgumentNullException>(() => writer.WriteByteArray("NullStream", null, 5)); Assert.Throws <ArgumentNullException>( () => writer.WriteByteArray("NullStream", null, 5, dummyByteArray)); // unacceptable nulls: WriteIntArray Assert.Throws <ArgumentNullException>(() => writer.WriteIntArray(null)); Assert.Throws <ArgumentNullException>(() => writer.WriteIntArray(null, 0, 5)); Assert.Throws <ArgumentNullException>(() => writer.WriteIntArray("NullIntArray", null)); Assert.Throws <ArgumentNullException>(() => writer.WriteIntArray("NullIntArray", null, 0, 5)); // non-readable streams are unacceptable Assert.Throws <ArgumentException>(() => writer.WriteByteArray(new NonReadableStream(), 0)); Assert.Throws <ArgumentException>( () => writer.WriteByteArray(new NonReadableStream(), 0, new byte[10])); Assert.Throws <ArgumentException>( () => writer.WriteByteArray("NonReadableStream", new NonReadableStream(), 0)); // trying to write array with out-of-range offset/count Assert.Throws <ArgumentOutOfRangeException>(() => writer.WriteByteArray(dummyByteArray, -1, 5)); Assert.Throws <ArgumentOutOfRangeException>(() => writer.WriteByteArray(dummyByteArray, 0, -1)); Assert.Throws <ArgumentException>(() => writer.WriteByteArray(dummyByteArray, 0, 6)); Assert.Throws <ArgumentException>(() => writer.WriteByteArray(dummyByteArray, 1, 5)); Assert.Throws <ArgumentOutOfRangeException>( () => writer.WriteByteArray("OutOfRangeByteArray", dummyByteArray, -1, 5)); Assert.Throws <ArgumentOutOfRangeException>( () => writer.WriteByteArray("OutOfRangeByteArray", dummyByteArray, 0, -1)); Assert.Throws <ArgumentException>( () => writer.WriteByteArray("OutOfRangeByteArray", dummyByteArray, 0, 6)); Assert.Throws <ArgumentException>( () => writer.WriteByteArray("OutOfRangeByteArray", dummyByteArray, 1, 5)); Assert.Throws <ArgumentOutOfRangeException>(() => writer.WriteIntArray(dummyIntArray, -1, 5)); Assert.Throws <ArgumentOutOfRangeException>(() => writer.WriteIntArray(dummyIntArray, 0, -1)); Assert.Throws <ArgumentException>(() => writer.WriteIntArray(dummyIntArray, 0, 6)); Assert.Throws <ArgumentException>(() => writer.WriteIntArray(dummyIntArray, 1, 5)); Assert.Throws <ArgumentOutOfRangeException>( () => writer.WriteIntArray("OutOfRangeIntArray", dummyIntArray, -1, 5)); Assert.Throws <ArgumentOutOfRangeException>( () => writer.WriteIntArray("OutOfRangeIntArray", dummyIntArray, 0, -1)); Assert.Throws <ArgumentException>( () => writer.WriteIntArray("OutOfRangeIntArray", dummyIntArray, 0, 6)); Assert.Throws <ArgumentException>( () => writer.WriteIntArray("OutOfRangeIntArray", dummyIntArray, 1, 5)); // out-of-range values for stream-reading overloads of WriteByteArray Assert.Throws <ArgumentOutOfRangeException>(() => writer.WriteByteArray(dummyStream, -1)); Assert.Throws <ArgumentOutOfRangeException>(() => writer.WriteByteArray("BadLength", dummyStream, -1)); Assert.Throws <ArgumentOutOfRangeException>( () => writer.WriteByteArray(dummyStream, -1, dummyByteArray)); Assert.Throws <ArgumentOutOfRangeException>( () => writer.WriteByteArray("BadLength", dummyStream, -1, dummyByteArray)); Assert.Throws <ArgumentException>(() => writer.WriteByteArray(dummyStream, 5, new byte[0])); Assert.Throws <ArgumentException>( () => writer.WriteByteArray("BadLength", dummyStream, 5, new byte[0])); // trying to read from non-readable stream Assert.Throws <ArgumentException>( () => writer.WriteByteArray("ByteStream", new NonReadableStream(), 0)); // finish too early Assert.Throws <NbtFormatException>(writer.Finish); writer.EndCompound(); writer.Finish(); // write tag after finishing Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtInt())); } } }
public void MissingNameTest() { using (var ms = new MemoryStream()) { NbtWriter writer = new NbtWriter(ms, "test"); // All tags (aside from list elements) must be named Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtByte(123))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtShort(123))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtInt(123))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtLong(123))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtFloat(123))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtDouble(123))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtString("value"))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtByteArray(new byte[0]))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtIntArray(new int[0]))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtLongArray(new long[0]))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtList(NbtTagType.Byte))); Assert.Throws <NbtFormatException>(() => writer.WriteTag(new NbtCompound())); } }
public void WriteNbtCompound(NbtCompound compound) { using var writer = new NbtWriter(BaseStream); writer.WriteTag(compound); }
public void WriteNbt(INbtTag nbt) { using var writer = new NbtWriter(BaseStream); writer.WriteTag(nbt); }
public void ErrorTest() { byte[] dummyByteArray = { 1, 2, 3, 4, 5 }; int[] dummyIntArray = { 1, 2, 3, 4, 5 }; byte[] dummyBuffer = new byte[1024]; MemoryStream dummyStream = new MemoryStream(dummyByteArray); using (var ms = new MemoryStream()) { // null constructor parameters, or a non-writable stream Assert.Throws<ArgumentNullException>(() => new NbtWriter(null, "root")); Assert.Throws<ArgumentNullException>(() => new NbtWriter(ms, null)); Assert.Throws<ArgumentException>(() => new NbtWriter(new NonWritableStream(), "root")); var writer = new NbtWriter(ms, "root"); { // use negative list size Assert.Throws<ArgumentOutOfRangeException>(() => writer.BeginList("list", NbtTagType.Int, -1)); writer.BeginList("listOfLists", NbtTagType.List, 1); Assert.Throws<ArgumentOutOfRangeException>(() => writer.BeginList(NbtTagType.Int, -1)); writer.BeginList(NbtTagType.Int, 0); writer.EndList(); writer.EndList(); writer.BeginList("list", NbtTagType.Int, 1); // invalid list type Assert.Throws<ArgumentOutOfRangeException>(() => writer.BeginList(NbtTagType.End, 0)); Assert.Throws<ArgumentOutOfRangeException>(() => writer.BeginList("list", NbtTagType.End, 0)); // call EndCompound when not in a compound Assert.Throws<NbtFormatException>(writer.EndCompound); // end list before all elements have been written Assert.Throws<NbtFormatException>(writer.EndList); // write the wrong kind of tag inside a list Assert.Throws<NbtFormatException>(() => writer.WriteShort(0)); // write a named tag where an unnamed tag is expected Assert.Throws<NbtFormatException>(() => writer.WriteInt("NamedInt", 0)); // write too many list elements writer.WriteTag(new NbtInt()); Assert.Throws<NbtFormatException>(() => writer.WriteInt(0)); writer.EndList(); // write a null tag Assert.Throws<ArgumentNullException>(() => writer.WriteTag(null)); // write an unnamed tag where a named tag is expected Assert.Throws<NbtFormatException>(() => writer.WriteTag(new NbtInt())); Assert.Throws<NbtFormatException>(() => writer.WriteInt(0)); // end a list when not in a list Assert.Throws<NbtFormatException>(writer.EndList); // unacceptable nulls: WriteString Assert.Throws<ArgumentNullException>(() => writer.WriteString(null)); Assert.Throws<ArgumentNullException>(() => writer.WriteString("NullString", null)); // unacceptable nulls: WriteByteArray from array Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray(null)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray(null, 0, 5)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray("NullByteArray", null)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray("NullByteArray", null, 0, 5)); // unacceptable nulls: WriteByteArray from stream Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray(null, 5)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray(null, 5, null)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray(dummyStream, 5, null)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray("NullBuffer", dummyStream, 5, null)); Assert.Throws<ArgumentNullException>(() => writer.WriteByteArray("NullStream", null, 5)); Assert.Throws<ArgumentNullException>( () => writer.WriteByteArray("NullStream", null, 5, dummyByteArray)); // unacceptable nulls: WriteIntArray Assert.Throws<ArgumentNullException>(() => writer.WriteIntArray(null)); Assert.Throws<ArgumentNullException>(() => writer.WriteIntArray(null, 0, 5)); Assert.Throws<ArgumentNullException>(() => writer.WriteIntArray("NullIntArray", null)); Assert.Throws<ArgumentNullException>(() => writer.WriteIntArray("NullIntArray", null, 0, 5)); // non-readable streams are unacceptable Assert.Throws<ArgumentException>(() => writer.WriteByteArray(new NonReadableStream(), 0)); Assert.Throws<ArgumentException>( () => writer.WriteByteArray(new NonReadableStream(), 0, new byte[10])); Assert.Throws<ArgumentException>( () => writer.WriteByteArray("NonReadableStream", new NonReadableStream(), 0)); // trying to write array with out-of-range offset/count Assert.Throws<ArgumentOutOfRangeException>(() => writer.WriteByteArray(dummyByteArray, -1, 5)); Assert.Throws<ArgumentOutOfRangeException>(() => writer.WriteByteArray(dummyByteArray, 0, -1)); Assert.Throws<ArgumentException>(() => writer.WriteByteArray(dummyByteArray, 0, 6)); Assert.Throws<ArgumentException>(() => writer.WriteByteArray(dummyByteArray, 1, 5)); Assert.Throws<ArgumentOutOfRangeException>( () => writer.WriteByteArray("OutOfRangeByteArray", dummyByteArray, -1, 5)); Assert.Throws<ArgumentOutOfRangeException>( () => writer.WriteByteArray("OutOfRangeByteArray", dummyByteArray, 0, -1)); Assert.Throws<ArgumentException>( () => writer.WriteByteArray("OutOfRangeByteArray", dummyByteArray, 0, 6)); Assert.Throws<ArgumentException>( () => writer.WriteByteArray("OutOfRangeByteArray", dummyByteArray, 1, 5)); Assert.Throws<ArgumentOutOfRangeException>(() => writer.WriteIntArray(dummyIntArray, -1, 5)); Assert.Throws<ArgumentOutOfRangeException>(() => writer.WriteIntArray(dummyIntArray, 0, -1)); Assert.Throws<ArgumentException>(() => writer.WriteIntArray(dummyIntArray, 0, 6)); Assert.Throws<ArgumentException>(() => writer.WriteIntArray(dummyIntArray, 1, 5)); Assert.Throws<ArgumentOutOfRangeException>( () => writer.WriteIntArray("OutOfRangeIntArray", dummyIntArray, -1, 5)); Assert.Throws<ArgumentOutOfRangeException>( () => writer.WriteIntArray("OutOfRangeIntArray", dummyIntArray, 0, -1)); Assert.Throws<ArgumentException>( () => writer.WriteIntArray("OutOfRangeIntArray", dummyIntArray, 0, 6)); Assert.Throws<ArgumentException>( () => writer.WriteIntArray("OutOfRangeIntArray", dummyIntArray, 1, 5)); // out-of-range values for stream-reading overloads of WriteByteArray Assert.Throws<ArgumentOutOfRangeException>(() => writer.WriteByteArray(dummyStream, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => writer.WriteByteArray("BadLength", dummyStream, -1)); Assert.Throws<ArgumentOutOfRangeException>( () => writer.WriteByteArray(dummyStream, -1, dummyByteArray)); Assert.Throws<ArgumentOutOfRangeException>( () => writer.WriteByteArray("BadLength", dummyStream, -1, dummyByteArray)); Assert.Throws<ArgumentException>(() => writer.WriteByteArray(dummyStream, 5, new byte[0])); Assert.Throws<ArgumentException>( () => writer.WriteByteArray("BadLength", dummyStream, 5, new byte[0])); // trying to read from non-readable stream Assert.Throws<ArgumentException>( () => writer.WriteByteArray("ByteStream", new NonReadableStream(), 0)); // finish too early Assert.Throws<NbtFormatException>(writer.Finish); writer.EndCompound(); writer.Finish(); // write tag after finishing Assert.Throws<NbtFormatException>(() => writer.WriteTag(new NbtInt())); } } }