internal static async IAsyncEnumerable <RawRecord> ReadRecords(ClientConnection conn, PipeReader reader, [EnumeratorCancellation] CancellationToken cancel) { while (!cancel.IsCancellationRequested) { byte[] handshakeHeader = await reader.ReadBytes(4, cancel); if (cancel.IsCancellationRequested) { break; } conn.AddProcessedMessage(handshakeHeader); var handshakeType = (HandshakeType)handshakeHeader[0]; handshakeHeader.AsSpan().Slice(1).ReadNumber(Length_NumBytes, out var len); var data = await reader.ReadBytes((int)len, cancel); conn.AddProcessedMessage(data); yield return(new RawRecord() { HandshakeType = handshakeType, Data = data }); } }
public static async Task <uint> ReadUInt32(this PipeReader reader, int numBytes, CancellationToken cancel) { return((await reader.ReadBytes(numBytes, cancel)).AsSpan().ToUInt32()); }
public static async Task <byte[]> ReadTLSData(this PipeReader reader, int lengthNumBytes, CancellationToken cancel) { int length = (int)(await reader.ReadUInt32(lengthNumBytes, cancel)); return(await reader.ReadBytes(length, cancel)); }
public static async Task <byte> ReadByte(this PipeReader reader, CancellationToken cancel) { return((await reader.ReadBytes(1, cancel))[0]); }