Пример #1
0
        public const int SettingSize = 6; // 2 bytes for the id, 4 bytes for the value.

        public static bool TryReadFrame(ref ReadOnlySequence <byte> buffer, Http2Frame frame, uint maxFrameSize, out ReadOnlySequence <byte> framePayload)
        {
            framePayload = ReadOnlySequence <byte> .Empty;

            if (buffer.Length < HeaderLength)
            {
                return(false);
            }

            var headerSlice = buffer.Slice(0, HeaderLength);
            var header      = headerSlice.ToSpan();

            var payloadLength = (int)Bitshifter.ReadUInt24BigEndian(header);

            if (payloadLength > maxFrameSize)
            {
                throw new Http2ConnectionErrorException("CoreStrings.FormatHttp2ErrorFrameOverLimit(payloadLength, maxFrameSize)", Http2ErrorCode.FRAME_SIZE_ERROR);
            }

            // Make sure the whole frame is buffered
            var frameLength = HeaderLength + payloadLength;

            if (buffer.Length < frameLength)
            {
                return(false);
            }

            frame.PayloadLength = payloadLength;
            frame.Type          = (Http2FrameType)header[TypeOffset];
            frame.Flags         = header[FlagsOffset];
            frame.StreamId      = (int)Bitshifter.ReadUInt31BigEndian(header.Slice(StreamIdOffset));

            var extendedHeaderLength = ReadExtendedFields(frame, buffer);

            // The remaining payload minus the extra fields
            framePayload = buffer.Slice(HeaderLength + extendedHeaderLength, payloadLength - extendedHeaderLength);
            buffer       = buffer.Slice(framePayload.End);

            return(true);
        }
Пример #2
0
 private static int ReadExtendedFields(Http2Frame frame, in ReadOnlySequence <byte> readableBuffer)