Couchbase .NET SDK __CB_SDK_VERSION__

Show / Hide Table of Contents

Interface IJsonStreamReader

Reads values and objects from a JSON stream asynchronously.

Inherited Members
IDisposable.Dispose()
Namespace: Couchbase.Core.IO.Serializers
Assembly: Couchbase.NetClient.dll
Syntax
public interface IJsonStreamReader : IDisposable

Properties

View Source

Depth

The current depth of the reader. Zero indicates ready to read the root object, one indicates an attribute on the root object, etc.

Declaration
int Depth { get; }
Property Value
Type Description
int
Remarks

Example paths: "metrics" == 1, "metrics.count" == 2, "results[0].abv" == 3.

View Source

Value

If the reader is stopped on a simple value attribute, returns the value.

Declaration
object? Value { get; }
Property Value
Type Description
object
View Source

ValueType

If the reader is stopped on a simple value attribute, returns the .NET type of the value. Otherwise, returns null.

Declaration
Type? ValueType { get; }
Property Value
Type Description
Type

Methods

View Source

InitializeAsync(CancellationToken)

Initializes the reader

Declaration
Task<bool> InitializeAsync(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
Task<bool>

true if successfully initialized.

Exceptions
Type Condition
InvalidOperationException

InitializeAsync should only be called once.

View Source

ReadArrayAsync<T>(Func<IJsonStreamReader, CancellationToken, Task<T>>, CancellationToken)

Reads an array of tokens at the current point in the stream.

Declaration
IAsyncEnumerable<T> ReadArrayAsync<T>(Func<IJsonStreamReader, CancellationToken, Task<T>> readElement, CancellationToken cancellationToken = default)
Parameters
Type Name Description
Func<IJsonStreamReader, CancellationToken, Task<T>> readElement

Function which reads each element of the array.

CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
IAsyncEnumerable<T>

An IAsyncEnumerable<T> to read the array.

Type Parameters
Name Description
T

Type of elements returned.

View Source

ReadObjectAsync<T>(CancellationToken)

Reads an object at the current point in the stream.

Declaration
Task<T> ReadObjectAsync<T>(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
Task<T>

The object read.

Type Parameters
Name Description
T

Type of the object to read.

Remarks

This method also supports reading literals such as strings, numbers, nulls, etc, given the correct type for T.

View Source

ReadToNextAttributeAsync(CancellationToken)

Reads until the next attribute is found in the stream. Returns the path to the attribute, or null if the end of the stream is reached.

Declaration
Task<string?> ReadToNextAttributeAsync(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
Task<string>

Path to the attribute relative to the overall stream, or null if the end of the stream is reached"

Remarks

The returned path is "." separated, and relative to the overall stream. For example, if the attribute "metrics" is on the root object, returns "metrics". If the attribute reached is "count" on the "metrics" object, the returned value is "metrics.count". Arrays are indicated with square brackets, for example "results[0].abv".

View Source

ReadTokenAsync(CancellationToken)

Reads a dynamic token at the current point in the stream.

Declaration
Task<IJsonToken> ReadTokenAsync(CancellationToken cancellationToken = default)
Parameters
Type Name Description
CancellationToken cancellationToken

Cancellation token.

Returns
Type Description
Task<IJsonToken>

The dynamic object.

Extension Methods

JsonStreamDeserializerExtensions.ReadObjectsAsync<T>(IJsonStreamReader, CancellationToken)
JsonStreamDeserializerExtensions.ReadTokensAsync(IJsonStreamReader, CancellationToken)
  • View Source
In this article
Back to top Copyright © 2020 Couchbase, Inc. All rights reserved.