| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.IO.Pipelines; |
| | | 4 | | |
| | | 5 | | namespace IceRpc.Internal; |
| | | 6 | | |
| | | 7 | | /// <summary>A PipeReader that does nothing and always throws InvalidOperationException except for Complete.</summary> |
| | | 8 | | internal sealed class InvalidPipeReader : PipeReader |
| | | 9 | | { |
| | | 10 | | /// <summary>Gets the invalid pipe reader singleton instance.</summary> |
| | 862 | 11 | | public static PipeReader Instance { get; } = new InvalidPipeReader(); |
| | | 12 | | |
| | | 13 | | private const string ExceptionMessage = "Reading an invalid pipe reader is not allowed."; |
| | | 14 | | |
| | 12 | 15 | | public override bool TryRead(out ReadResult result) => throw new InvalidOperationException(ExceptionMessage); |
| | | 16 | | |
| | | 17 | | public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default) => |
| | 2 | 18 | | throw new InvalidOperationException(ExceptionMessage); |
| | | 19 | | |
| | 0 | 20 | | public override void AdvanceTo(SequencePosition consumed) => throw new InvalidOperationException(ExceptionMessage); |
| | | 21 | | |
| | | 22 | | public override void AdvanceTo(SequencePosition consumed, SequencePosition examined) => |
| | 0 | 23 | | throw new InvalidOperationException(ExceptionMessage); |
| | | 24 | | |
| | 0 | 25 | | public override void CancelPendingRead() => throw new InvalidOperationException(ExceptionMessage); |
| | | 26 | | |
| | | 27 | | public override void Complete(Exception? exception = null) |
| | 162 | 28 | | { |
| | | 29 | | // no-op |
| | 162 | 30 | | } |
| | | 31 | | |
| | 5 | 32 | | private InvalidPipeReader() |
| | 5 | 33 | | { |
| | | 34 | | // ensures there is only one instance |
| | 5 | 35 | | } |
| | | 36 | | } |