示例#1
0
        public static TagWriter CreateWriter(NbtFormat format, Stream stream)
        {
            TagWriter writer;

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            switch (format)
            {
            case NbtFormat.Binary:
                writer = new BinaryTagWriter(stream);
                break;

            case NbtFormat.Xml:
                writer = new XmlTagWriter(stream);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(format), format, "Invalid format.");
            }

            return(writer);
        }
示例#2
0
        public void GetFormatXmlTest()
        {
            // arrange
            var             fileName = ComplexXmlDataFileName;
            const NbtFormat expected = NbtFormat.Xml;

            // act
            var actual = NbtDocument.GetDocumentFormat(fileName);

            // assert
            Assert.Equal(expected, actual);
        }
示例#3
0
        public void GetFormatInvalidTest()
        {
            // arrange
            var             fileName = BadFileName;
            const NbtFormat expected = NbtFormat.Unknown;

            // act
            var actual = NbtDocument.GetDocumentFormat(fileName);

            // assert
            Assert.Equal(expected, actual);
        }
示例#4
0
        public void GetFormatDeflateBinaryTest()
        {
            // arrange
            var             fileName = DeflateComplexDataFileName;
            const NbtFormat expected = NbtFormat.Binary;

            // act
            var actual = NbtDocument.GetDocumentFormat(fileName);

            // assert
            Assert.Equal(expected, actual);
        }
示例#5
0
        private static TagReader GetReader(NbtFormat format, Stream stream)
        {
            TagReader reader;

            switch (format)
            {
            case NbtFormat.Binary:
                reader = new BinaryTagReader(stream);
                break;

            case NbtFormat.Xml:
                reader = new XmlTagReader(stream);
                break;

            default:
                throw new InvalidDataException("Unrecognized or unsupported file format.");
            }

            return(reader);
        }
示例#6
0
 public NbtDocument()
 {
     _format       = NbtFormat.Binary;
     _documentRoot = (TagCompound)TagFactory.CreateTag(TagType.Compound);
 }