We can call ReadAsync() and examine a buffer for read bytes...
PipeReader reader = ...;
ReadResult readResult = await reader.ReadAsync();
ReadOnlySequence<byte> buffer = readResult.Buffer;
long availableBytes = buffer.Length
If the length does not increase from before the call to ReadAsync, does that indicate the end of the pipe (no more bytes to read)? If not then what is the correct way of detecting 'end of pipe'?
We can signal consumption of bytes in the buffer like so:
reader.AdvanceTo(count);
And then check if there are any unconsumed bytes, or the possibility of future bytes being supplied (i.e. the producer has not yet signalled that it has stopped adding new bytes to the pipe)
readResult.IsCompleted
But if I am looking for a sequence (or sequences) in the buffer and waiting for a complete sequence before consuming it, then IsComplete appears to remain false even when the buffer contains all of the available bytes, and the producer has signalled completion.
Thanks.