Table of Contents

Struct ShapeShiftDocumentReader<T, TEncoder, TDecoder>

Namespace
ShapeShift
Assembly
ShapeShift.dll

Enables incremental, low-allocation enumeration of a sequence of whole top-level values sharing one decoder, such as newline-delimited JSON (NDJSON) or a buffer containing several concatenated MessagePack values.

public struct ShapeShiftDocumentReader<T, TEncoder, TDecoder> : IDisposable where TEncoder : IEncoder, allows ref struct where TDecoder : IDecoder, allows ref struct

Type Parameters

T

The type of each top-level value.

TEncoder

The type of encoder used by the serializer that created this reader.

TDecoder

The type of decoder that supplies the serialized data.

Implements
Inherited Members

Remarks

Create an instance with CreateDocumentReader<T>(ITypeShape<T>, CancellationToken) or a format-specific convenience overload (e.g. JsonSerializer.CreateDocumentReader).

Unlike ShapeShiftSequenceReader<T, TEncoder, TDecoder>, this reader does not expect (or consume) any enclosing vector brackets: it simply reads whole values, one after another, until the decoder reports EndDocument. As with ShapeShiftSequenceReader<T, TEncoder, TDecoder>, this type does not store the TDecoder itself; the same decoder value must be passed by ref to every call to MoveNext(ref TDecoder).

Always call Dispose() (or use a using statement) when finished with a reader, so that pooled resources it may hold can be released.

Properties

Current

Gets the value most recently read by MoveNext(ref TDecoder).

public readonly T? Current { get; }

Property Value

T

Remarks

This property's value is undefined before the first call to MoveNext(ref TDecoder), and after any call to it that returns false.

Methods

Dispose()

Releases any pooled resources held by this reader.

public void Dispose()

MoveNext(ref TDecoder)

Advances to the next top-level value, reading it into Current.

public bool MoveNext(ref TDecoder decoder)

Parameters

decoder TDecoder

The decoder that supplies the data. On every call, the same value (by ref) that was supplied to the previous call must be given, so this reader observes the decoder's position as it was left after the previous value was read.

Returns

bool

true if another value was read into Current; false if the decoder has reached the end of its input (EndDocument).

Exceptions

InvalidOperationException

Thrown if this method is called again after it has already returned false once.