Ejemplo n.º 1
0
        private bool ParsePreface(ReadOnlyBuffer<byte> readableBuffer, out SequencePosition consumed, out SequencePosition examined)
        {
            consumed = readableBuffer.Start;
            examined = readableBuffer.End;

            if (readableBuffer.Length < ClientPreface.Length)
            {
                return false;
            }

            var span = readableBuffer.IsSingleSegment
                ? readableBuffer.First.Span
                : readableBuffer.ToSpan();

            for (var i = 0; i < ClientPreface.Length; i++)
            {
                if (ClientPreface[i] != span[i])
                {
                    throw new Exception("Invalid HTTP/2 connection preface.");
                }
            }

            consumed = examined = readableBuffer.GetPosition(readableBuffer.Start, ClientPreface.Length);
            return true;
        }
Ejemplo n.º 2
0
 public LinePackageInfo Filter(ref ReadOnlyBuffer <byte> buffer)
 {
     return(new LinePackageInfo
     {
         Line = Encodings.Utf8.ToString(buffer.ToSpan())
     });
 }