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(); } }
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(); } }
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()); }
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(); }
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); }
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(); } }
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); }
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(); } }
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(); } }
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(); } }
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; }
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; }
private byte[] ReadBinaryCore(StreamSegment current) { UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin); return _reader.ReadBytes(current.ContentLength); }
private string ReadStringCore(StreamSegment current) { UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin); return _reader.ReadString(); }
private int ReadIntegerCore(StreamSegment current) { UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin); return _reader.ReadInt32(); }
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(); } }
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(); } }
private int ReadIntegerCore(StreamSegment current) { UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin); return(_reader.ReadInt32()); }
private string ReadStringCore(StreamSegment current) { UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin); return(_reader.ReadString()); }
private byte[] ReadBinaryCore(StreamSegment current) { UnderlyingStream.Seek(current.ContentStartOffset, SeekOrigin.Begin); return(_reader.ReadBytes(current.ContentLength)); }
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(); } }
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(); } }