internal static NbtTag ReadUnknownTag(NbtBinaryReader readStream) { NbtTagType nbtTagType = (NbtTagType)readStream.ReadByte(); //readStream.ReadTagType(); if (nbtTagType == NbtTagType.Unknown) { return(new NbtCompound("")); } NbtTag nbtTag; switch (nbtTagType) { case NbtTagType.End: throw new EndOfStreamException(); case NbtTagType.List: nbtTag = (NbtTag) new NbtList(); break; case NbtTagType.Compound: nbtTag = (NbtTag) new NbtCompound(); break; default: throw new Exception("Unsupported tag type found in NBT_Tag: " + (object)nbtTagType); } nbtTag.Name = readStream.ReadString(); if (nbtTag.ReadTag(readStream)) { return(nbtTag); } throw new Exception("Given NBT stream does not start with a proper TAG"); }
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()); }
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; }
internal static bool ReadTag(this NbtTag tag, NbtBinaryReader readStream) { while (true) { NbtTag nbtTag; do { NbtTagType nbtTagType = readStream.ReadTagType(); switch (nbtTagType) { case NbtTagType.End: return(true); case NbtTagType.Byte: nbtTag = (NbtTag) new NbtByte(); break; case NbtTagType.Short: nbtTag = (NbtTag) new NbtShort(); break; case NbtTagType.Int: nbtTag = (NbtTag) new NbtInt(); break; case NbtTagType.Long: nbtTag = (NbtTag) new NbtLong(); break; case NbtTagType.Float: nbtTag = (NbtTag) new NbtFloat(); break; case NbtTagType.Double: nbtTag = (NbtTag) new NbtDouble(); break; case NbtTagType.ByteArray: nbtTag = (NbtTag) new NbtByteArray(); break; case NbtTagType.String: nbtTag = (NbtTag) new NbtString(); break; case NbtTagType.List: nbtTag = (NbtTag) new NbtList(); break; case NbtTagType.Compound: nbtTag = (NbtTag) new NbtCompound(); break; case NbtTagType.IntArray: nbtTag = (NbtTag) new NbtIntArray(); break; case NbtTagType.LongArray: nbtTag = (NbtTag) new NbtLongArray(); break; case NbtTagType.Unknown: return(true); break; default: throw new FormatException("Unsupported tag type found in NBT_Compound: " + (object)nbtTagType); } //nbtTag.Parent = (NbtTag) this; nbtTag.Name = readStream.ReadString(); }while (!nbtTag.ReadTag(readStream)); switch (tag.TagType) { case NbtTagType.Compound: NbtCompound compound = (NbtCompound)tag; compound.Add(nbtTag); break; case NbtTagType.List: NbtList list = (NbtList)tag; list.Add(nbtTag); break; } } }
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; 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; }
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; }
static string GetRootNameInternal(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(); }