private 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: case NbtTagType.LongArray: TagLength = reader.ReadInt32(); atValue = true; break; case NbtTagType.List: // Setting state to error in case reader throws state = NbtParseState.Error; 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: state = NbtParseState.Error; throw new NbtFormatException("Trying to read tag of unknown type."); } }
private 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()); }
private void LoadFromStreamInternal([NotNull] Stream stream, [CanBeNull] 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; }