Often a protocol knows how much data it is waiting for (TLS frames being one example, size headered binary protocols being another).
Instead of ReadAsync() then you check the header and you see you don't have enough, so you ReadAsync() check if you have enough and continue doing loops until you have a complete frame. If you could do a "ReadAsync(xxxxx)" and it wouldn't return unless there was an error/complete or at least that amount of data was available it would solve extra looping in every downstream protocol
Proposed API
public abstract partial class PipeReader
{
+ public virtual ValueTask<ReadResult> ReadAsync(int minimumBytes, CancellationToken cancellationToken = default);
}
/cc @Drawaes
Often a protocol knows how much data it is waiting for (TLS frames being one example, size headered binary protocols being another).
Instead of ReadAsync() then you check the header and you see you don't have enough, so you ReadAsync() check if you have enough and continue doing loops until you have a complete frame. If you could do a "ReadAsync(xxxxx)" and it wouldn't return unless there was an error/complete or at least that amount of data was available it would solve extra looping in every downstream protocol
Proposed API
public abstract partial class PipeReader { + public virtual ValueTask<ReadResult> ReadAsync(int minimumBytes, CancellationToken cancellationToken = default); }/cc @Drawaes