public override async Task InitializeAsync(CancellationToken cancellationToken = default) { if (_rows != null) { throw new InvalidOperationException("Cannot initialize more than once."); } if (ResponseStream != null) { var body = await _deserializer.DeserializeAsync <ViewResultData>(ResponseStream, cancellationToken).ConfigureAwait(false); MetaData = new ViewMetaData { TotalRows = body.total_rows }; _rows = body.rows?.Select(p => new ViewRow <TKey, TValue> { Id = p.id, Key = p.key, Value = p.value }) ?? Enumerable.Empty <IViewRow <TKey, TValue> >(); } else { _rows = Enumerable.Empty <IViewRow <TKey, TValue> >(); } DecodeSpan?.Finish(); }
private async Task ReadResponseAttributes(CancellationToken cancellationToken) { if (_reader == null) { // Should not be possible throw new InvalidOperationException("_reader is null"); } if (MetaData == null) { MetaData = new ViewMetaData(); } while (true) { var path = await _reader.ReadToNextAttributeAsync(cancellationToken).ConfigureAwait(false); if (path == null) { // End of stream break; } if (path == "total_rows" && _reader.Value != null && _reader.ValueType == typeof(long)) { MetaData.TotalRows = (uint)(long)_reader.Value; } else if (path == "rows") { // we've reached the 'rows' element, return now so when we enumerate we start from here _hasReadToRows = true; return; } } // if we got here, there was no 'rows' element in the stream _hasFinishedReading = true; }