protected ITag ReadTag(ReadTagOptions options, TagType defaultTagType) { ITag result; TagType type; this.InitializeReader(); type = this.ReadTagType(defaultTagType); result = TagFactory.CreateTag(type); if ((options & ReadTagOptions.IgnoreName) == 0) { string name; name = _reader.GetAttribute("name"); if (string.IsNullOrEmpty(name)) { name = _reader.Name; } result.Name = name; } if ((options & ReadTagOptions.IgnoreValue) == 0) { result.Value = this.ReadTagValue(result); } return result; }
public virtual ITag ReadTag(ReadTagOptions options) { int rawType; ITag result; rawType = _stream.ReadByte(); result = TagFactory.CreateTag((TagType)rawType); if (result.Type != TagType.End && (options & ReadTagOptions.IgnoreName) == 0) { result.Name = this.ReadString(); } if ((options & ReadTagOptions.IgnoreValue) == 0) { object value; switch (result.Type) { case TagType.End: value = null; break; case TagType.Byte: value = this.ReadByte(); break; case TagType.Short: value = this.ReadShort(); break; case TagType.Int: value = this.ReadInt(); break; case TagType.IntArray: value = this.ReadIntArray(); break; case TagType.Long: value = this.ReadLong(); break; case TagType.Float: value = this.ReadFloat(); break; case TagType.Double: value = this.ReadDouble(); break; case TagType.ByteArray: value = this.ReadByteArray(); break; case TagType.String: value = this.ReadString(); break; case TagType.List: value = this.ReadCollection((TagList)result); break; case TagType.Compound: value = this.ReadDictionary((TagCompound)result); break; default: throw new InvalidDataException($"Unrecognized tag type: {rawType}"); } result.Value = value; } return result; }
public virtual TagCompound ReadDocument(Stream stream, ReadTagOptions options) { TagCompound tag; if (stream.IsGzipCompressed()) { using (Stream decompressionStream = new GZipStream(stream, CompressionMode.Decompress)) { _stream = decompressionStream; tag = (TagCompound)this.ReadTag(options); } } else if (stream.IsDeflateCompressed()) { using (Stream decompressionStream = new DeflateStream(stream, CompressionMode.Decompress)) { _stream = decompressionStream; tag = (TagCompound)this.ReadTag(options); } } else if (stream.PeekNextByte() == (int)TagType.Compound) { _stream = stream; tag = (TagCompound)this.ReadTag(options); } else { throw new InvalidDataException("Source stream does not contain a NBT document."); } return tag; }
public virtual ITag ReadTag(ReadTagOptions options) { return this.ReadTag(options, TagType.None); }
public virtual TagCompound ReadDocument(Stream stream, ReadTagOptions options) { TagCompound result; bool createReader; createReader = _reader == null; if (createReader) { _reader = XmlReader.Create(stream); } result = (TagCompound)this.ReadTag(options); if (createReader) { _reader = null; } return result; }
private void ReadChildValues(ICollection<ITag> value, ReadTagOptions options, TagType listType) { int depth; this.SkipWhitespace(); depth = _reader.Depth; if (_reader.NodeType != XmlNodeType.EndElement) { do { if (_reader.NodeType == XmlNodeType.Element) { ITag child; child = this.ReadTag(options, listType); value.Add(child); } else { _reader.Read(); } } while (_reader.Depth == depth); } else { _reader.Read(); this.SkipWhitespace(); } }