public static bool TryParse(ReadOnlyMemory <byte> bytes, out StreamDataBlockedFrame result, out ReadOnlyMemory <byte> remainings)
        {
            result     = new StreamDataBlockedFrame();
            remainings = ReadOnlyMemory <byte> .Empty;

            var type = FrameType.Parse(bytes, out var afterTypeBytes);

            if (!type.IsStreamDataBlocked())
            {
                return(false);
            }

            var streamId  = StreamId.Parse(afterTypeBytes, out var afterStreamIdBytes);
            var dataLimit = VariableLengthEncoding.Decode32(afterStreamIdBytes.Span, out var decodedLength);

            result     = new StreamDataBlockedFrame(streamId, dataLimit);
            remainings = afterStreamIdBytes.Slice(decodedLength);

            return(true);
        }
Exemple #2
0
        public static bool TryParse(ReadOnlyMemory <byte> bytes, out StopSendingFrame result, out ReadOnlyMemory <byte> remainings)
        {
            result     = new StopSendingFrame();
            remainings = ReadOnlyMemory <byte> .Empty;

            var type = FrameType.Parse(bytes, out var afterTypeRemainings);

            if (!type.IsStopSending())
            {
                return(false);
            }

            var streamId         = StreamId.Parse(afterTypeRemainings, out var afterStreamIdBytes);
            var applicationError = Error.ParseApplication(afterStreamIdBytes, out var afterApplicationErrorBytes);

            result     = new StopSendingFrame(streamId, applicationError);
            remainings = afterApplicationErrorBytes;

            return(true);
        }
        public static bool TryParse(ReadOnlyMemory <byte> bytes, out ResetStreamFrame result, out ReadOnlyMemory <byte> remainings)
        {
            result     = new ResetStreamFrame();
            remainings = ReadOnlyMemory <byte> .Empty;

            var type = FrameType.Parse(bytes, out var afterTypeRemainings);

            if (!type.IsResetStream())
            {
                return(false);
            }

            var streamId  = StreamId.Parse(afterTypeRemainings, out var afterStreamIdBytes);
            var error     = Error.ParseApplication(afterStreamIdBytes, out var afterApplicationErrorBytes);
            var finalSize = VariableLengthEncoding.Decode32(afterApplicationErrorBytes.Span, out var decodedLength);

            result     = new ResetStreamFrame(streamId, error, finalSize);
            remainings = afterApplicationErrorBytes.Slice(decodedLength);

            return(true);
        }
        public static bool TryParse(ReadOnlyMemory <byte> bytes, out StreamFrame result, out ReadOnlyMemory <byte> remainings)
        {
            result     = new StreamFrame();
            remainings = ReadOnlyMemory <byte> .Empty;

            var type = FrameType.Parse(bytes, out var afterTypeBytes);

            if (!type.IsStream())
            {
                return(false);
            }

            var streamId = StreamId.Parse(afterTypeBytes, out var afterStreamIdBytes);
            var offset   = ParseOffset(afterStreamIdBytes, type, out var afterOffsetBytes);
            var data     = ParseData(afterOffsetBytes, type, out var afterDataBytes);
            var isFinal  = type.HasFinal();

            result     = new StreamFrame(streamId, offset, isFinal, data);
            remainings = afterDataBytes;

            return(true);
        }