Exemple #1
0
        public object ReadValue(StreamSegment current)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }
            if (current.UnderlyingStream != UnderlyingStream)
            {
                throw new ArgumentException("Invalid argument.", nameof(current));
            }
            switch (current.ContentType)
            {
            case StreamSegmentType.Null:
                return(null);

            case StreamSegmentType.Integer:
                return(ReadIntegerCore(current));

            case StreamSegmentType.String:
                return(ReadStringCore(current));

            case StreamSegmentType.Binary:
                return(ReadBinaryCore(current));

            case StreamSegmentType.Dictionary:
                return(ReadDictionaryCore(current));

            case StreamSegmentType.Array:
                return(ReadArrayCore(current));

            default:
                throw new InvalidDataException();
            }
        }
Exemple #2
0
 public object ReadValue(StreamSegment current)
 {
     if (current == null)
     {
         throw new ArgumentNullException(nameof(current));
     }
     if (current.UnderlyingStream != UnderlyingStream)
     {
         throw new ArgumentException("Invalid argument.", nameof(current));
     }
     switch (current.ContentType)
     {
         case StreamSegmentType.Null:
             return null;
         case StreamSegmentType.Integer:
             return ReadIntegerCore(current);
         case StreamSegmentType.String:
             return ReadStringCore(current);
         case StreamSegmentType.Binary:
             return ReadBinaryCore(current);
         case StreamSegmentType.Dictionary:
             return ReadDictionaryCore(current);
         case StreamSegmentType.Array:
             return ReadArrayCore(current);
         default:
             throw new InvalidDataException();
     }
 }
Exemple #3
0
 public StreamSegment ReadNext(StreamSegment current)
 {
     if (current == null)
     {
         throw new ArgumentNullException(nameof(current));
     }
     if (current.Next >= UnderlyingStream.Length)
     {
         return(null);
     }
     UnderlyingStream.Seek(current.Next, SeekOrigin.Begin);
     return(ReadSegment());
 }
Exemple #4
0
 public StreamSegment ReadNext(StreamSegment current)
 {
     if (current == null)
     {
         throw new ArgumentNullException(nameof(current));
     }
     if (current.Next >= UnderlyingStream.Length)
     {
         return null;
     }
     UnderlyingStream.Seek(current.Next, SeekOrigin.Begin);
     return ReadSegment();
 }
Exemple #5
0
        private object[] ReadArrayCore(StreamSegment current)
        {
            UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
            var indices = new int[current.ContentLength / 4];

            for (int i = 0; i < indices.Length; i++)
            {
                indices[i] = _reader.ReadInt32();
            }
            var result = new object[current.ContentLength / 4];

            for (int i = 0; i < indices.Length; i++)
            {
                result[i] = ReadValue(ReadSegment(indices[i]));
            }
            return(result);
        }
Exemple #6
0
        public string ReadInteger(StreamSegment current)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }
            if (current.UnderlyingStream != UnderlyingStream)
            {
                throw new ArgumentException("Invalid argument.", nameof(current));
            }
            switch (current.ContentType)
            {
            case StreamSegmentType.Integer:
                return(ReadStringCore(current));

            default:
                throw new InvalidDataException();
            }
        }
Exemple #7
0
        private Dictionary <string, Lazy <object> > ReadDictionaryLazyCore(StreamSegment current)
        {
            UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
            var indices = new int[current.ContentLength / 4];

            for (int i = 0; i < indices.Length; i++)
            {
                indices[i] = _reader.ReadInt32();
            }
            var result = new Dictionary <string, Lazy <object> >();

            for (int i = 0; i < indices.Length;)
            {
                var keySeg   = ReadSegment(indices[i++]);
                var valueSeg = ReadSegment(indices[i++]);
                result[ReadString(keySeg)] = new Lazy <object>(() => ReadValue(valueSeg), false);
            }
            return(result);
        }
Exemple #8
0
        public object[] ReadArray(StreamSegment current)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }
            if (current.UnderlyingStream != UnderlyingStream)
            {
                throw new ArgumentException("Invalid argument.", nameof(current));
            }
            switch (current.ContentType)
            {
            case StreamSegmentType.Null:
                return(null);

            case StreamSegmentType.Array:
                return(ReadArrayCore(current));

            default:
                throw new InvalidDataException();
            }
        }
Exemple #9
0
        public Dictionary <string, Lazy <object> > ReadDictionaryLazy(StreamSegment current)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }
            if (current.UnderlyingStream != UnderlyingStream)
            {
                throw new ArgumentException("Invalid argument.", nameof(current));
            }
            switch (current.ContentType)
            {
            case StreamSegmentType.Null:
                return(null);

            case StreamSegmentType.Dictionary:
                return(ReadDictionaryLazyCore(current));

            default:
                throw new InvalidDataException();
            }
        }
Exemple #10
0
        public Stream ReadBinaryAsStream(StreamSegment current)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }
            if (current.UnderlyingStream != UnderlyingStream)
            {
                throw new ArgumentException("Invalid argument.", nameof(current));
            }
            switch (current.ContentType)
            {
            case StreamSegmentType.Null:
                return(Stream.Null);

            case StreamSegmentType.Binary:
                // todo : use underlying stream later.
                return(new MemoryStream(ReadBinaryCore(current)));

            default:
                throw new InvalidDataException();
            }
        }
Exemple #11
0
 private Dictionary<string, Lazy<object>> ReadDictionaryLazyCore(StreamSegment current)
 {
     UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
     var indices = new int[current.ContentLength / 4];
     for (int i = 0; i < indices.Length; i++)
     {
         indices[i] = _reader.ReadInt32();
     }
     var result = new Dictionary<string, Lazy<object>>();
     for (int i = 0; i < indices.Length;)
     {
         var keySeg = ReadSegment(indices[i++]);
         var valueSeg = ReadSegment(indices[i++]);
         result[ReadString(keySeg)] = new Lazy<object>(() => ReadValue(valueSeg), false);
     }
     return result;
 }
Exemple #12
0
 private object[] ReadArrayCore(StreamSegment current)
 {
     UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
     var indices = new int[current.ContentLength / 4];
     for (int i = 0; i < indices.Length; i++)
     {
         indices[i] = _reader.ReadInt32();
     }
     var result = new object[current.ContentLength / 4];
     for (int i = 0; i < indices.Length; i++)
     {
         result[i] = ReadValue(ReadSegment(indices[i]));
     }
     return result;
 }
Exemple #13
0
 private byte[] ReadBinaryCore(StreamSegment current)
 {
     UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
     return _reader.ReadBytes(current.ContentLength);
 }
Exemple #14
0
 private string ReadStringCore(StreamSegment current)
 {
     UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
     return _reader.ReadString();
 }
Exemple #15
0
 private int ReadIntegerCore(StreamSegment current)
 {
     UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
     return _reader.ReadInt32();
 }
Exemple #16
0
 public Dictionary<string, Lazy<object>> ReadDictionaryLazy(StreamSegment current)
 {
     if (current == null)
     {
         throw new ArgumentNullException(nameof(current));
     }
     if (current.UnderlyingStream != UnderlyingStream)
     {
         throw new ArgumentException("Invalid argument.", nameof(current));
     }
     switch (current.ContentType)
     {
         case StreamSegmentType.Null:
             return null;
         case StreamSegmentType.Dictionary:
             return ReadDictionaryLazyCore(current);
         default:
             throw new InvalidDataException();
     }
 }
Exemple #17
0
 public object[] ReadArray(StreamSegment current)
 {
     if (current == null)
     {
         throw new ArgumentNullException(nameof(current));
     }
     if (current.UnderlyingStream != UnderlyingStream)
     {
         throw new ArgumentException("Invalid argument.", nameof(current));
     }
     switch (current.ContentType)
     {
         case StreamSegmentType.Null:
             return null;
         case StreamSegmentType.Array:
             return ReadArrayCore(current);
         default:
             throw new InvalidDataException();
     }
 }
Exemple #18
0
 private int ReadIntegerCore(StreamSegment current)
 {
     UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
     return(_reader.ReadInt32());
 }
Exemple #19
0
 private string ReadStringCore(StreamSegment current)
 {
     UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
     return(_reader.ReadString());
 }
Exemple #20
0
 private byte[] ReadBinaryCore(StreamSegment current)
 {
     UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin);
     return(_reader.ReadBytes(current.ContentLength));
 }
Exemple #21
0
 public string ReadInteger(StreamSegment current)
 {
     if (current == null)
     {
         throw new ArgumentNullException(nameof(current));
     }
     if (current.UnderlyingStream != UnderlyingStream)
     {
         throw new ArgumentException("Invalid argument.", nameof(current));
     }
     switch (current.ContentType)
     {
         case StreamSegmentType.Integer:
             return ReadStringCore(current);
         default:
             throw new InvalidDataException();
     }
 }
Exemple #22
0
 public Stream ReadBinaryAsStream(StreamSegment current)
 {
     if (current == null)
     {
         throw new ArgumentNullException(nameof(current));
     }
     if (current.UnderlyingStream != UnderlyingStream)
     {
         throw new ArgumentException("Invalid argument.", nameof(current));
     }
     switch (current.ContentType)
     {
         case StreamSegmentType.Null:
             return Stream.Null;
         case StreamSegmentType.Binary:
             // todo : use underlying stream later.
             return new MemoryStream(ReadBinaryCore(current));
         default:
             throw new InvalidDataException();
     }
 }