Interface IJsonStreamReader
Reads values and objects from a JSON stream asynchronously.
Inherited Members
Namespace: Couchbase.Core.IO.Serializers
Assembly: Couchbase.NetClient.dll
Syntax
public interface IJsonStreamReader : IDisposable
Properties
| Edit this page View SourceDepth
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.
Value
If the reader is stopped on a simple value attribute, returns the value.
Declaration
object? Value { get; }
Property Value
Type | Description |
---|---|
object |
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
| Edit this page View SourceInitializeAsync(CancellationToken)
Initializes the reader
Declaration
Task<bool> InitializeAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Cancellation token. |
Returns
Type | Description |
---|---|
Task<bool> |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | InitializeAsync should only be called once. |
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. |
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
.
ReadToNextAttributeAsync(CancellationToken)
Reads until the next attribute is found in the stream. Returns the path to the attribute,
or
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 |
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".
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. |