internal override bool ReadTag(NbtBinaryReader readStream) {
     if (readStream.Selector != null && !readStream.Selector(this)) {
         readStream.ReadDouble();
         return false;
     }
     Value = readStream.ReadDouble();
     return true;
 }
        /// <summary> Initializes a new instance of the NbtReader class. </summary>
        /// <param name="stream"> Stream to read from. </param>
        /// <param name="bigEndian"> Whether NBT data is in Big-Endian encoding. </param>
        /// <exception cref="ArgumentNullException"> <paramref name="stream"/> is <c>null</c>. </exception>
        /// <exception cref="ArgumentException"> <paramref name="stream"/> is not readable. </exception>
        public NbtReader([NotNull] Stream stream, bool bigEndian)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            SkipEndTags    = true;
            CacheTagValues = false;
            ParentTagType  = NbtTagType.Unknown;
            TagType        = NbtTagType.Unknown;

            canSeekStream = stream.CanSeek;
            if (canSeekStream)
            {
                streamStartOffset = stream.Position;
            }

            reader = new NbtBinaryReader(stream, bigEndian);
        }
 internal override void SkipTag(NbtBinaryReader readStream) {
     readStream.ReadDouble();
 }
        internal override bool ReadTag(NbtBinaryReader readStream) {
            int length = readStream.ReadInt32();
            if (length < 0) {
                throw new NbtFormatException("Negative length given in TAG_Int_Array");
            }

            if (readStream.Selector != null && !readStream.Selector(this)) {
                readStream.Skip(length*sizeof(int));
                return false;
            }

            Value = new int[length];
            for (int i = 0; i < length; i++) {
                Value[i] = readStream.ReadInt32();
            }
            return true;
        }
 internal override void SkipTag(NbtBinaryReader readStream) {
     int length = readStream.ReadInt32();
     if (length < 0) {
         throw new NbtFormatException("Negative length given in TAG_Int_Array");
     }
     readStream.Skip(length*sizeof(int));
 }
Example #6
0
 internal override void SkipTag(NbtBinaryReader readStream) {
     readStream.ReadInt32();
 }
        internal override bool ReadTag(NbtBinaryReader readStream) {
            int length = readStream.ReadInt32();
            if (length < 0) {
                throw new NbtFormatException("Negative length given in TAG_Byte_Array");
            }

            if (readStream.Selector != null && !readStream.Selector(this)) {
                readStream.Skip(length);
                return false;
            }
            Value = readStream.ReadBytes(length);
            if (Value.Length < length) {
                throw new EndOfStreamException();
            }
            return true;
        }
 internal override void SkipTag(NbtBinaryReader readStream) {
     readStream.SkipString();
 }
Example #9
0
        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();
        }
Example #10
0
        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;
        }