예제 #1
0
        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
                });
            }
        }