コード例 #1
0
 internal override bool ReadTag(NbtBinaryReader readStream) {
     if (readStream.Selector != null && !readStream.Selector(this)) {
         readStream.ReadDouble();
         return false;
     }
     Value = readStream.ReadDouble();
     return true;
 }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
 internal override void SkipTag(NbtBinaryReader readStream) {
     readStream.ReadDouble();
 }
コード例 #4
0
        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;
        }
コード例 #5
0
 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));
 }
コード例 #6
0
 internal override void SkipTag(NbtBinaryReader readStream) {
     readStream.ReadInt32();
 }
コード例 #7
0
        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;
        }
コード例 #8
0
 internal override void SkipTag(NbtBinaryReader readStream) {
     readStream.SkipString();
 }
コード例 #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();
        }
コード例 #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;
        }