Class ResettablePipeReaderDecorator
- Namespace
- IceRpc
- Assembly
- IceRpc.dll
Represents a PipeReader decorator that doesn't consume the data from the decoratee to allow reading again this data from the beginning after being reset.
public sealed class ResettablePipeReaderDecorator : PipeReader
- Inheritance
-
ResettablePipeReaderDecorator
- Inherited Members
- Extension Methods
Remarks
The decorator becomes non-resettable if the decoratee's buffered data exceeds the maximum buffer size provided to ResettablePipeReaderDecorator(PipeReader, int) or if the reading from the decoratee fails with an exception other than OperationCanceledException.
Calling Complete(Exception?) on the decorator doesn't complete the decoratee to allow reading again the data after the decorator is reset. It's therefore important to make the decorator non-resettable by setting IsResettable to false to complete the decoratee.
Constructors
ResettablePipeReaderDecorator(PipeReader, int)
Constructs a resettable pipe reader decorator.
public ResettablePipeReaderDecorator(PipeReader decoratee, int maxBufferSize)
Parameters
decoratee
PipeReaderThe pipe reader being decorated.
maxBufferSize
intThe maximum size of buffered data in bytes.
Properties
IsResettable
Gets or sets a value indicating whether this decorator can be reset.
public bool IsResettable { get; set; }
Property Value
Remarks
This property can only be set to false. If IsResettable is true and Complete(Exception?) was called, the decoratee is completed.
Methods
AdvanceTo(SequencePosition)
Moves forward the pipeline's read cursor to after the consumed data. No data is consumed while IsResettable value is true.
public override void AdvanceTo(SequencePosition consumed)
Parameters
consumed
SequencePositionMarks the extent of the data that has been successfully processed.
- See Also
AdvanceTo(SequencePosition, SequencePosition)
Moves forward the pipeline's read cursor to after the consumed data. No data is consumed while IsResettable value is true.
public override void AdvanceTo(SequencePosition consumed, SequencePosition examined)
Parameters
consumed
SequencePositionMarks the extent of the data that has been successfully processed.
examined
SequencePositionMarks the extent of the data that has been read and examined.
- See Also
CancelPendingRead()
Cancels the pending ReadAsync(CancellationToken) operation without causing it to throw and without completing the PipeReader. If there is no pending operation, this cancels the next operation.
public override void CancelPendingRead()
- See Also
Complete(Exception?)
Signals to the producer that the consumer is done reading.
public override void Complete(Exception? exception = null)
Parameters
exception
ExceptionOptional Exception indicating a failure that's causing the pipeline to complete.
Remarks
If IsResettable value is true, Complete(Exception?) is not called on the decoratee to allow reading again the data after a call to Reset(). To complete the decoratee, IsResettable must be set to false.
- See Also
ReadAsync(CancellationToken)
Asynchronously reads a sequence of bytes from the current PipeReader.
public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask<ReadResult>
A ValueTask<TResult> representing the asynchronous read operation.
- See Also
ReadAtLeastAsyncCore(int, CancellationToken)
Asynchronously reads a sequence of bytes from the current PipeReader.
protected override ValueTask<ReadResult> ReadAtLeastAsyncCore(int minimumSize, CancellationToken cancellationToken = default)
Parameters
minimumSize
intThe minimum length that needs to be buffered in order for the call to return.
cancellationToken
CancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask<ReadResult>
A ValueTask<TResult> representing the asynchronous read operation.
Reset()
Resets this pipe reader.
public void Reset()
Exceptions
- InvalidOperationException
Thrown if IsResettable is false or if reading is in progress.
TryRead(out ReadResult)
Attempts to synchronously read data from the PipeReader.
public override bool TryRead(out ReadResult result)
Parameters
result
ReadResultWhen this method returns true, this value is set to a ReadResult instance that represents the result of the read call; otherwise, this value is set to default.
Returns
- bool
true if data was available, or if the call was canceled or the writer was completed; otherwise, false.
- See Also
-
TryRead(out ReadResult)