FdbRangeChunk

Namespace: FoundationDB.Client · class

Implements: IReadOnlyList<KeyValuePair<Slice, Slice>>, IEnumerable<KeyValuePair<Slice, Slice>>, IEnumerable, IReadOnlyCollection<KeyValuePair<Slice, Slice>>, IDisposable

Page of results from a GetRangeAsync operation

Remarks

If a pool was specified in the , then this instance MUST be disposed; otherwise, rented buffers will not be returned to the pool

Constructors

FdbRangeChunk

FdbRangeChunk(KeyValuePair<Slice, Slice>[] items, bool hasMore, int iteration, FdbRangeOptions options, Slice first, Slice last, int totalBytes, SliceOwner buffer)

Properties

Count

int Count { get; }

Returns the number of results in this chunk

FetchMode

FdbFetchMode FetchMode { get; }

Specifies if the chunk contains only keys, only values, or both (default)

First

Slice First { get; }

Returns the last item in the chunk

Note that if the range is reversed, then the last item will be LESS than the first!

HasMore

bool HasMore { get; }

Set to true if there are more results in the database than could fit in a single chunk

IsEmpty

bool IsEmpty { get; }

Returns true if the chunk does not contain any item.

Item

KeyValuePair<Slice, Slice> Item { get; }

KeyValuePair<Slice, Slice> Item { get; }

ReadOnlySpan<KeyValuePair<Slice, Slice>> Item { get; }

Items

KeyValuePair<Slice, Slice>[] Items { get; }

Keys and Values that were read from the database

The entries are sorted by keys, either with an ascending or descending order, depending on the value of

Iteration

int Iteration { get; }

Iteration number of this chunk, starting from 1 for the first page

This value must be passed to subsequent calls to to continue reading; otherwise, the streaming will not behave properly.

Keys

KeysCollection Keys { get; }

Last

Slice Last { get; }

Returns the first item in the chunk

Note that if the range is reversed, then the first item will be GREATER than the last !

Options

FdbRangeOptions Options { get; }

Options used to perform this operation

They can be passed again to , together with Iteration + 1 to continue reading from the database.

Reversed

bool Reversed { get; }

Set to true if the original range read was reversed (meaning the items are in reverse lexicographic order

TotalBytes

int TotalBytes { get; }

Sum of the size (in bytes) of all the keys and values read from the database

Values

ValuesCollection Values { get; }

Methods

AppendValues

void AppendValues(ref SliceWriter writer)

Append all the values into a buffer, in sequential order

  • writer — Buffer where to write all the values

Returns: Total number of bytes written to the buffer

ConcatValues

Slice ConcatValues()

Append all the values into a buffer, in sequential order

Returns: Slice with all values copied in sequential order, or Nil if the chunk is empty

This is useful when using a range queries to read all the chunks of a single entity. Since this method will allocate and copy all the results, if the expected size is expected to be large, prefer iterating over the instead!

CopyTo

void CopyTo(KeyValuePair<Slice, Slice>[] array, int offset)

Decode

KeyValuePair<TKey, TValue>[] Decode<TKey, TValue>(Func<Slice, TKey> keyHandler, Func<Slice, TValue> valueHandler)

Decode the content of this chunk into an array of typed key/value pairs

  • keyHandler — Lambda that can decode the keys of this chunk
  • valueHandler — Lambda that can decode the values of this chunk

Returns: Array of decoded key/value pairs, or an empty array if the chunk doesn't have any results

DecodeKeys

T[] DecodeKeys<T>(Func<Slice, T> handler)

Decode the content of this chunk into an array of typed keys

  • handler — Instance used to decode the keys of this chunk

Returns: Array of decoded keys, or an empty array if the chunk doesn't have any results

DecodeValues

T[] DecodeValues<T>(Func<Slice, T> handler)

Decode the content of this chunk into an array of typed values

  • handler — Lambda that can decode the values of this chunk

Returns: Array of decoded values, or an empty array if the chunk doesn't have any results

T[] DecodeValues<T>(IValueEncoder<T> valueEncoder)

Decode the content of this chunk into an array of typed values

  • valueEncoder — Instance used to decode the values of this chunk

Returns: Array of decoded values, or an empty array if the chunk doesn't have any results

Dispose

void Dispose()

Releases any buffer used by this chunk, if it was pooled

CAUTION: Any key or value slice obtained from this instance MUST NOT be used after this has been disposed!

This does nothing if the no pool was specified in the FdbRangeOptions

If any pooled content must survive this instance, it MUST be copied to a new Slice, or transferred to another SliceOwner instance!

GetEnumerator

ChunkEnumerator GetEnumerator()

ItemRef

KeyValuePair<Slice, Slice> ItemRef(int index)

Return a reference to the result at the specified index

ToArray

KeyValuePair<Slice, Slice>[] ToArray()