Exemplo n.º 1
0
        /// <summary>
        /// Makes a deep copy of the node.
        /// </summary>
        /// <returns>A new list node containing new subnodes representing the same data.</returns>
        public override TagNode Copy()
        {
            TagNodeList list = new TagNodeList(_type);

            foreach (TagNode item in _items)
            {
                list.Add(item.Copy());
            }
            return(list);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs a default <see cref="TagNodeList"/> satisfying the constraints of this node.
        /// </summary>
        /// <returns>A <see cref="TagNodeList"/> with a sensible default value.  If a length is specified, default child <see cref="TagNode"/> objects of the necessary type will be created and added to the <see cref="TagNodeList"/>.</returns>
        public override TagNode BuildDefaultTree()
        {
            if (_length == 0)
            {
                return(new TagNodeList(_type));
            }

            TagNodeList list = new TagNodeList(_type);

            for (int i = 0; i < _length; i++)
            {
                list.Add(_subschema.BuildDefaultTree());
            }

            return(list);
        }
Exemplo n.º 3
0
        private TagNode ReadList()
        {
            int gzByte = _stream.ReadByte();

            if (gzByte == -1)
            {
                throw new NBTException(NBTException.MSG_GZIP_ENDOFSTREAM);
            }

            TagNodeList val = new TagNodeList((TagType)gzByte);

            if (val.ValueType > (TagType)Enum.GetValues(typeof(TagType)).GetUpperBound(0))
            {
                throw new NBTException(NBTException.MSG_READ_TYPE);
            }

            byte[] lenBytes = new byte[4];
            _stream.Read(lenBytes, 0, 4);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(lenBytes);
            }

            int length = BitConverter.ToInt32(lenBytes, 0);

            if (length < 0)
            {
                throw new NBTException(NBTException.MSG_READ_NEG);
            }

            if (val.ValueType == TagType.TAG_END)
            {
                return(new TagNodeList(TagType.TAG_BYTE));
            }

            for (int i = 0; i < length; i++)
            {
                val.Add(ReadValue(val.ValueType));
            }

            return(val);
        }