void ReadTagHeader(bool readName) { // Setting state to error in case reader throws NbtParseState oldState = state; state = NbtParseState.Error; TagsRead++; TagName = (readName ? reader.ReadString() : null); valueCache = null; TagLength = 0; atValue = false; ListType = NbtTagType.Unknown; switch (TagType) { case NbtTagType.Byte: case NbtTagType.Short: case NbtTagType.Int: case NbtTagType.Long: case NbtTagType.Float: case NbtTagType.Double: case NbtTagType.String: atValue = true; state = oldState; break; case NbtTagType.IntArray: case NbtTagType.ByteArray: case NbtTagType.LongArray: TagLength = reader.ReadInt32(); if (TagLength < 0) { throw new NbtFormatException("Negative array length given: " + TagLength); } atValue = true; state = oldState; break; case NbtTagType.List: ListType = reader.ReadTagType(); TagLength = reader.ReadInt32(); if (TagLength < 0) { throw new NbtFormatException("Negative tag length given: " + TagLength); } state = NbtParseState.AtListBeginning; break; case NbtTagType.Compound: state = NbtParseState.AtCompoundBeginning; break; default: // This should not happen unless NbtBinaryReader is bugged throw new NbtFormatException("Trying to read tag of unknown type."); } }
public void LoadFromStream(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } using (var decStream = new GZipStream(stream, CompressionMode.Decompress, true)) { // Size of buffers that are used to avoid frequent reads from / writes to compressed streams BufferedStream buffered = new BufferedStream(decStream, 8 * 1024); // Make sure the first byte in this file is the tag for a TAG_Compound int header = buffered.ReadByte(); if (header < 0) { throw new EndOfStreamException(); } if (header != (int)NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } var reader = new NbtBinaryReader(buffered, true); var rootCompound = new NbtCompound(reader.ReadString()); rootCompound.ReadTag(reader); RootTag = rootCompound; } }
void LoadFromStreamInternal([NotNull] Stream stream, [CanBeNull] TagSelector tagSelector) { // Make sure the first byte in this file is the tag for a TAG_Compound if (FileVersion != NbtVersion.Legacy) { stream.Read(new byte[8], 0, 8); } int firstByte = stream.ReadByte(); if (firstByte < 0) { throw new EndOfStreamException(); } if (firstByte != (int)NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } var reader = new NbtBinaryReader(stream, BigEndian) { Selector = tagSelector, UseVarInt = UseVarInt }; var rootCompound = new NbtCompound(reader.ReadString()); rootCompound.ReadTag(reader); RootTag = rootCompound; }
internal override bool ReadTag(NbtBinaryReader readStream) { if (readStream.Selector != null && !readStream.Selector(this)) { readStream.SkipString(); return(false); } Value = readStream.ReadString(); return(true); }
void ReadTagHeader(bool readName) { TagsRead++; TagName = (readName ? reader.ReadString() : null); valueCache = null; TagLength = 0; atValue = false; ListType = NbtTagType.Unknown; switch (TagType) { case NbtTagType.Byte: case NbtTagType.Short: case NbtTagType.Int: case NbtTagType.Long: case NbtTagType.Float: case NbtTagType.Double: case NbtTagType.String: atValue = true; break; case NbtTagType.IntArray: case NbtTagType.ByteArray: TagLength = reader.ReadInt32(); atValue = true; break; case NbtTagType.List: ListType = reader.ReadTagType(); TagLength = reader.ReadInt32(); state = NbtParseState.AtListBeginning; break; case NbtTagType.Compound: state = NbtParseState.AtCompoundBeginning; break; default: throw new NbtFormatException("Trying to read tag of unknown type."); } }
static string GetRootNameInternal([NotNull] Stream stream, bool bigEndian) { if (stream == null) { throw new ArgumentNullException("stream"); } NbtBinaryReader reader = new NbtBinaryReader(stream, bigEndian); if (reader.ReadTagType() != NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } return(reader.ReadString()); }
internal override void ReadTag(NbtBinaryReader readStream) { while (true) { NbtTagType nextTag = readStream.ReadTagType(); if (nextTag == NbtTagType.End) { return; } NbtTag newTag = Construct(nextTag); newTag.Name = readStream.ReadString(); newTag.ReadTag(readStream); tags.Add(newTag.Name, newTag); } }
static string GetRootNameInternal([NotNull] Stream stream, bool bigEndian) { Debug.Assert(stream != null); int firstByte = stream.ReadByte(); if (firstByte < 0) { throw new EndOfStreamException(); } else if (firstByte != (int)NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } var reader = new NbtBinaryReader(stream, bigEndian); return(reader.ReadString()); }
void LoadFromStreamInternal([NotNull] Stream stream, [CanBeNull] TagSelector tagSelector) { if (stream == null) { throw new ArgumentNullException("stream"); } // Make sure the first byte in this file is the tag for a TAG_Compound if (stream.ReadByte() != (int)NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } NbtBinaryReader reader = new NbtBinaryReader(stream, BigEndian) { Selector = tagSelector }; var rootCompound = new NbtCompound(reader.ReadString()); rootCompound.ReadTag(reader); RootTag = rootCompound; }
void LoadFromStreamInternal(Stream stream, TagSelector tagSelector) { // Make sure the first byte in this file is the tag for a TAG_Compound int firstByte = stream.ReadByte(); if (firstByte < 0) { throw new EndOfStreamException(); } if (firstByte != (int)NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } var reader = new NbtBinaryReader(stream, BigEndian) { Selector = tagSelector }; var rootCompound = new NbtCompound(reader.ReadString()); rootCompound.ReadTag(reader); RootTag = rootCompound; }
internal override void ReadTag(NbtBinaryReader readStream) { Value = readStream.ReadString(); }
internal static NbtTag ReadUnknownTag(NbtBinaryReader readStream) { NbtTagType nextTag = readStream.ReadTagType(); NbtTag newTag; switch (nextTag) { case NbtTagType.End: throw new EndOfStreamException(); //case NbtTagType.Byte: // newTag = new NbtByte(); // break; //case NbtTagType.Short: // newTag = new NbtShort(); // break; //case NbtTagType.Int: // newTag = new NbtInt(); // break; //case NbtTagType.Long: // newTag = new NbtLong(); // break; //case NbtTagType.Float: // newTag = new NbtFloat(); // break; //case NbtTagType.Double: // newTag = new NbtDouble(); // break; //case NbtTagType.ByteArray: // newTag = new NbtByteArray(); // break; //case NbtTagType.String: // newTag = new NbtString(); // break; case NbtTagType.List: newTag = new NbtList(); break; case NbtTagType.Compound: newTag = new NbtCompound(); break; //case NbtTagType.IntArray: // newTag = new NbtIntArray(); // break; //case NbtTagType.LongArray: // newTag = new NbtLongArray(); // break; default: throw new NbtFormatException("Unsupported tag type found in NBT_Tag: " + nextTag); } newTag.Name = readStream.ReadString(); if (newTag.ReadTag(readStream)) { return(newTag); } throw new NbtFormatException("Given NBT stream does not start with a proper TAG"); }
void LoadFromStreamInternal([NotNull] Stream stream, [CanBeNull] TagSelector tagSelector) { // Make sure the first byte in this file is the tag for a TAG_Compound if (stream.ReadByte() != (int)NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } var reader = new NbtBinaryReader(stream, BigEndian) { Selector = tagSelector }; var rootCompound = new NbtCompound(reader.ReadString()); rootCompound.ReadTag(reader); RootTag = rootCompound; }
static string GetRootNameInternal([NotNull] Stream stream, bool bigEndian) { if (stream == null) throw new ArgumentNullException("stream"); if (stream.ReadByte() != (int)NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } var reader = new NbtBinaryReader(stream, bigEndian); return reader.ReadString(); }
internal override bool ReadTag(NbtBinaryReader readStream) { if (Parent != null && readStream.Selector != null && !readStream.Selector(this)) { SkipTag(readStream); return(false); } while (true) { NbtTagType nextTag = readStream.ReadTagType(); NbtTag newTag; switch (nextTag) { case NbtTagType.End: return(true); case NbtTagType.Byte: newTag = new NbtByte(); break; case NbtTagType.Short: newTag = new NbtShort(); break; case NbtTagType.Int: newTag = new NbtInt(); break; case NbtTagType.Long: newTag = new NbtLong(); break; case NbtTagType.Float: newTag = new NbtFloat(); break; case NbtTagType.Double: newTag = new NbtDouble(); break; case NbtTagType.ByteArray: newTag = new NbtByteArray(); break; case NbtTagType.String: newTag = new NbtString(); break; case NbtTagType.List: newTag = new NbtList(); break; case NbtTagType.Compound: newTag = new NbtCompound(); break; case NbtTagType.IntArray: newTag = new NbtIntArray(); break; case NbtTagType.LongArray: newTag = new NbtLongArray(); break; default: throw new NbtFormatException("Unsupported tag type found in NBT_Compound: " + nextTag); } newTag.Parent = this; newTag.Name = readStream.ReadString(); if (newTag.ReadTag(readStream)) { // ReSharper disable AssignNullToNotNullAttribute // newTag.Name is never null tags.Add(newTag.Name, newTag); // ReSharper restore AssignNullToNotNullAttribute } } }
internal override bool ReadTag( NbtBinaryReader readStream ) { if( readStream.Selector != null && !readStream.Selector( this ) ) { readStream.SkipString(); return false; } Value = readStream.ReadString(); return true; }
static string GetRootNameInternal([NotNull] Stream stream, bool bigEndian) { Debug.Assert(stream != null); int firstByte = stream.ReadByte(); if (firstByte < 0) { throw new EndOfStreamException(); } else if (firstByte != (int)NbtTagType.Compound) { throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound"); } var reader = new NbtBinaryReader(stream, bigEndian); return reader.ReadString(); }