public TagCompound(Stream stream) { while (true) { int tagByte = stream.ReadByte(); if (tagByte == -1) { throw new EndOfStreamException(); } if (!NbtRegistry.IsRegistered((TagType)tagByte)) { throw new IOException("Unexpected tag type: " + tagByte); } TagType type = (TagType)tagByte; if (type == TagType.End) { break; } TagString name = new TagString(stream); Tag value = NbtRegistry.Read(stream, type); _tags[name.Data] = value; } }
public TagList(Stream stream) { int valByte = stream.ReadByte(); if (valByte == -1) { throw new EndOfStreamException(); } if (!NbtRegistry.IsRegistered((TagType)valByte)) { throw new IOException("Unexpected tag type: " + valByte); } ValueType = (TagType)valByte; byte[] lenBytes = new byte[4]; if (stream.Read(lenBytes, 0, 4) < 4) { throw new EndOfStreamException(); } if (BitConverter.IsLittleEndian) { Array.Reverse(lenBytes); } int length = BitConverter.ToInt32(lenBytes, 0); if (length < 0) { throw new IOException("Unexpected stream data"); } for (int i = 0; i < length; i++) { Add(NbtRegistry.Read(stream, ValueType)); } }