Example #1
0
        async Task <InputChunk> MakeChunk(IChunk chunk, Scan scan, long from, long to)
        {
            while (true)
            {
                if (chunk == null)
                {
                    return(null);
                }
                InputChunk res = await Decompress(chunk);

                if (res != null)
                {
                    return(res);
                }
                switch (scan)
                {
                case Scan.None:
                    return(null);

                case Scan.Forward:
                    chunk = await _reader.ReadFirstAsync(chunk.BeginPosition + 1, to);

                    break;

                case Scan.Backward:
                    chunk = await _reader.ReadLastAsync(from, chunk.BeginPosition);

                    break;

                default:
                    Debug.Fail("Invalid scan");
                    break;
                }
            }
        }
Example #2
0
            public async Task <bool> MoveNextAsync(CancellationToken cancel)
            {
                if (_done)
                {
                    return(false);
                }

                if (_chunk == null)
                {
                    _chunk = await _reader._reader.ReadAtPartitionAsync(_from, _to, u => new DateTime(u.Long0) > _after);
                }
                else
                {
                    _chunk.Dispose();
                    _chunk = await _reader._reader.ReadFirstAsync(_next, _to);
                }

                if (_chunk == null)
                {
                    _done = true;
                    return(false);
                }
                else
                {
                    Current = new TimeSeriesChunk(_chunk, _reader.Decoder);
                    _next   = _chunk.EndPosition;
                    return(true);
                }
            }
Example #3
0
 public void Reset()
 {
     _chunk?.Dispose();
     _chunk = null;
     _next  = 0;
     _done  = false;
 }
Example #4
0
            public TimeSeriesChunk(InputChunk chunk, ITimeSeriesDecoder <T> decoder)
            {
                BeginPosition = chunk.BeginPosition;
                EndPosition   = chunk.EndPosition;
                _data         = Decode();

                IEnumerable <T> Decode()
                {
                    decoder.DecodePrimary(chunk, new DateTime(chunk.UserData.Long0, DateTimeKind.Utc), out T val);
                    yield return(val);

                    while (decoder.DecodeSecondary(chunk, out val))
                    {
                        yield return(val);
                    }
                }
            }
Example #5
0
        static async Task <InputChunk> Decompress(IChunk chunk)
        {
            var content = new byte[chunk.ContentLength];

            if (!await chunk.ReadContentAsync(content, 0))
            {
                return(null);
            }
            var res = new InputChunk(chunk.BeginPosition, chunk.EndPosition, chunk.UserData);

            try {
                Compression.DecompressTo(content, 0, content.Length, res);
            } catch {
                res.Dispose();
                // This translation of decompression errors into missing chunks is the only reason
                // why ReadAtPartitionAsync is implemented in BufferedReader rather than ChunkReader.
                return(null);
            }
            return(res);
        }