Esempio n. 1
0
File: Nbt.cs Progetto: Tobi406/SM3
        public void NbtReadBasic()
        {
            var nbtReader        = new NbtReader(_testBytes);
            var compound         = nbtReader.ReadCompound();
            var originalCompound = (NbtCompound)_testCompound.Value["hello world"];
            var readCompound     = (NbtCompound)compound.Value["hello world"];

            Assert.AreEqual(originalCompound.Value["name"], readCompound.Value["name"]);
        }
		public object Deserialize(NbtReader nbtReader)
		{
			NbtTagInfo tagInfo = nbtReader.ReadTagInfo();
			if (tagInfo.Type != NbtTagType.Compound)
				throw new FormatException("the deserialized stream must contain root tag which is compound.");

			NbtCompound root = nbtReader.ReadCompound(tagInfo);

			return DeserializeTag(root, m_type);
		}
        public void NbtParser_ParseCompoundShouldFail_BecauseExpectedValue()
        {
            // Arrange
            IStringReader reader = new StringReader("{foo:}");

            // Act
            ReadResults readResults = NbtReader.ReadCompound(reader, out _);

            // Assert
            Assert.IsFalse(readResults.Successful);
        }
        public object Deserialize(NbtReader nbtReader)
        {
            NbtTagInfo tagInfo = nbtReader.ReadTagInfo();

            if (tagInfo.Type != NbtTagType.Compound)
            {
                throw new FormatException("the deserialized stream must contain root tag which is compound.");
            }

            NbtCompound root = nbtReader.ReadCompound(tagInfo);

            return(DeserializeTag(root, m_type));
        }
Esempio n. 5
0
		public void ReadCompound_EndOfStreamException()
		{
			// Arrange
			NbtTagInfo tagInfo = (NbtTagInfo)new byte[] { 0x0A, 0x00, 0x04 };
			byte[] data = new byte[] { 0x61, 0x73 };

			MemoryStream stream = new MemoryStream(data);

			NbtReader reader = new NbtReader(stream);

			// Act
			NbtCompound result = reader.ReadCompound(tagInfo);
		}
Esempio n. 6
0
		public void ReadCompound_ObjectDisposedException()
		{
			// Arrange
			NbtTagInfo tagInfo = (NbtTagInfo)new byte[] { 0x0A, 0x00, 0x04 };
			byte[] data = new byte[] {
				0x61, 0x73, 0x64, 0x66,
			    0x06, 0x00, 0x04, 0x61, 0x73, 0x64, 0x66, 0x40, 0x09, 0x21, 0xFB, 0x54, 0x44, 0x2D, 0x18, // double
			    0x02, 0x00, 0x04, 0x61, 0x73, 0x64, 0x66, 0x30, 0x39, // short
				0x00 // TAG_End
			};

			MemoryStream stream = new MemoryStream(data);

			NbtReader reader = new NbtReader(stream);

			stream.Close();

			// Act
			NbtCompound result = reader.ReadCompound(tagInfo);
		}
Esempio n. 7
0
		public void ReadCompound_Normal()
		{
			// Arrange
			NbtTagInfo tagInfo = (NbtTagInfo)new byte[] { 0x0A, 0x00, 0x04 };
			byte[] data = new byte[] {
				0x61, 0x73, 0x64, 0x66,
			    0x06, 0x00, 0x04, 0x61, 0x73, 0x64, 0x66, 0x40, 0x09, 0x21, 0xFB, 0x54, 0x44, 0x2D, 0x18, // double
			    0x02, 0x00, 0x04, 0x61, 0x73, 0x64, 0x66, 0x30, 0x39, // short
				0x00 // TAG_End
			};

			MemoryStream stream = new MemoryStream(data);

			NbtReader reader = new NbtReader(stream);

			NbtTagType expectedTagType = NbtTagType.Compound;
			string expectedName = "asdf";
			NbtTag[] expectedValue = new NbtTag[]
			{
				new NbtDouble("asdf", 3.14159265358979311599796346854E0),
				new NbtShort("asdf", 12345)
			};

			// Act
			NbtCompound result = reader.ReadCompound(tagInfo);

			// Assert
			Assert.AreEqual(expectedName, result.Name);
			Assert.AreEqual(expectedTagType, result.Type);

			Assert.AreEqual(expectedValue[0].Name, result.Value[0].Name);
			Assert.AreEqual(expectedValue[0].Type, result.Value[0].Type);
			Assert.AreEqual(expectedValue[0].GetValue(), result.Value[0].GetValue());

			Assert.AreEqual(expectedValue[1].Name, result.Value[1].Name);
			Assert.AreEqual(expectedValue[1].Type, result.Value[1].Type);
			Assert.AreEqual(expectedValue[1].GetValue(), result.Value[1].GetValue());
		}