コード例 #1
0
 public void PartialReadTest()
 {
     // read the whole thing as one tag
     TestFiles.AssertValueTest(PartialReadTestInternal(new NbtFile(TestFiles.MakeValueTest())));
     TestFiles.AssertNbtSmallFile(PartialReadTestInternal(TestFiles.MakeSmallFile()));
     TestFiles.AssertNbtBigFile(PartialReadTestInternal(new NbtFile(TestFiles.Big)));
 }
コード例 #2
0
    public void ValueTest()
    {
        // write one named tag for every value type, and read it back
        using var ms = new MemoryStream();

        var writer = new NbtWriter(ms, "root");

        Assert.Equal(ms, writer.BaseStream);
        {
            writer.WriteByte("byte", 1);
            writer.WriteShort("short", 2);
            writer.WriteInt("int", 3);
            writer.WriteLong("long", 4L);
            writer.WriteFloat("float", 5f);
            writer.WriteDouble("double", 6d);
            writer.WriteByteArray("byteArray", new byte[] { 10, 11, 12 });
            writer.WriteIntArray("intArray", new[] { 20, 21, 22 });
            writer.WriteString("string", "123");
        }
        Assert.False(writer.IsDone);
        writer.EndCompound();
        Assert.True(writer.IsDone);
        writer.Finish();

        ms.Position = 0;
        var file = new NbtFile();

        file.LoadFromStream(ms, NbtCompression.None);

        TestFiles.AssertValueTest(file);
    }
コード例 #3
0
ファイル: NbtReaderTests.cs プロジェクト: Eastrall/Redstone
 public void PartialBatchReadTest()
 {
     // read the whole thing as one tag, in batches of 4 bytes
     // Verifies fix for https://github.com/fragmer/fNbt/issues/26
     TestFiles.AssertValueTest(PartialReadTestInternal(new NbtFile(TestFiles.MakeValueTest()), 4));
     TestFiles.AssertNbtSmallFile(PartialReadTestInternal(TestFiles.MakeSmallFile(), 4));
     TestFiles.AssertNbtBigFile(PartialReadTestInternal(new NbtFile(TestFiles.Big), 4));
 }
コード例 #4
0
        public void ReadAsTagTest3()
        {
            // read values as tags
            byte[] testData = new NbtFile(TestFiles.MakeValueTest()).SaveToBuffer(NbtCompression.None);
            var    reader   = new NbtReader(new MemoryStream(testData));
            var    root     = new NbtCompound("root");

            // skip root
            reader.ReadToFollowing();
            reader.ReadToFollowing();

            while (!reader.IsAtStreamEnd)
            {
                root.Add(reader.ReadAsTag());
            }

            TestFiles.AssertValueTest(new NbtFile(root));
        }
コード例 #5
0
 public void ReadAsTagTest2()
 {
     // read the whole thing as one tag
     byte[] testData = new NbtFile(TestFiles.MakeValueTest()).SaveToBuffer(NbtCompression.None);
     {
         var reader = new NbtReader(new MemoryStream(testData));
         var root   = (NbtCompound)reader.ReadAsTag();
         TestFiles.AssertValueTest(new NbtFile(root));
     }
     {
         // Try the same thing but with end tag skipping disabled
         var reader = new NbtReader(new MemoryStream(testData))
         {
             SkipEndTags = false
         };
         var root = (NbtCompound)reader.ReadAsTag();
         TestFiles.AssertValueTest(new NbtFile(root));
     }
 }
コード例 #6
0
    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.True(writer.IsDone);
            writer.Finish();
        }
        ms.Position = 0;
        var  file      = new NbtFile();
        long bytesRead = file.LoadFromBuffer(ms.ToArray(), 0, (int)ms.Length, NbtCompression.None);

        Assert.Equal(bytesRead, ms.Length);
        TestFiles.AssertValueTest(file);
    }