/// <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); }
/// <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); }
private TagNode ReadList() { var gzByte = _stream.ReadByte(); if (gzByte == -1) { throw new NBTException(NBTException.MSG_GZIP_ENDOFSTREAM); } var val = new TagNodeList((TagType)gzByte); if (val.ValueType > (TagType)Enum.GetValues(typeof(TagType)).GetUpperBound(0)) { throw new NBTException(NBTException.MSG_READ_TYPE); } var lenBytes = new byte[4]; _stream.Read(lenBytes, 0, 4); if (BitConverter.IsLittleEndian) { Array.Reverse(lenBytes); } var 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 (var i = 0; i < length; i++) { val.Add(ReadValue(val.ValueType)); } return(val); }