Beispiel #1
0
            public NbtTag Deserialize(BinaryReader br, bool requireName)
            {
                string name = null;

                if (requireName)
                {
                    name = br.ReadTagString();
                }

                var elementType = br.ReadTagType();
                var count       = br.ReadInt32().ToggleEndian();

                if (count <= 0)
                {
                    return(new NbtList(elementType, name));
                }

                var elements = new NbtTag[count];

                for (var i = 0; i < count; ++i)
                {
                    elements[i] = NbtTagSerializer.DeserializeTag(br, elementType, false);
                }

                return(new NbtList(elements, name));
            }
Beispiel #2
0
        public NbtCompound ReadAsNbtTag()
        {
            NbtCompound nbt;

            using (MemoryStream ms = new MemoryStream(_span.ToArray()))
            {
                using (var br = new BinaryReader(ms, Encoding.UTF8, false))
                {
                    nbt = NbtTagSerializer.DeserializeTag <NbtCompound>(br);
                }

                Advance((int)ms.Position);
            }

            return(nbt);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NbtFile"/> class.<para />
        /// 从流中初始化 Nbt 数据
        /// </summary>
        /// <param name="stream">要从中初始化数据的流</param>
        /// <param name="leaveOpen">读取完成后保持流的打开状态</param>
        public NbtFile(Stream stream, bool leaveOpen = true)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanRead)
            {
                throw new ArgumentException("流不可读", nameof(stream));
            }

            Contract.EndContractBlock();

            using (var br = new BinaryReader(stream, Encoding.UTF8, leaveOpen))
            {
                RootTag = NbtTagSerializer.DeserializeTag <NbtCompound>(br);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NbtFile"/> class.<para />
        /// 从流中初始化 Nbt 数据
        /// </summary>
        /// <param name="stream">要从中初始化数据的流</param>
        public NbtFile(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanRead)
            {
                throw new ArgumentException("流不可读", nameof(stream));
            }

            Contract.EndContractBlock();

            using (var br = new BinaryReader(stream))
            {
                _rootTag = NbtTagSerializer.DeserializeTag <NbtCompound>(br, false);
            }
        }
Beispiel #5
0
            public NbtTag Deserialize(BinaryReader br, bool requireName)
            {
                string name = null;

                if (requireName)
                {
                    name = br.ReadTagString();
                }

                var elements = new List <NbtTag>();

                while (true)
                {
                    var curElement = NbtTagSerializer.DeserializeTag(br);
                    if (curElement.TagType == NbtTagType.End)
                    {
                        break;
                    }

                    elements.Add(curElement);
                }

                return(new NbtCompound(elements, name));
            }