Example #1
0
        public static WritingContext StartWriting(MemoryCursor cursor,
                                                  AckDelay delay,
                                                  PacketNumber largestAcknowledged,
                                                  int beforLargestAcknowledgedLength,
                                                  AckEcnCounts?ecnFeedback = null)
        {
            if (beforLargestAcknowledgedLength < 0)
            {
                throw new EncodingException();
            }

            FrameType
            .CreateAck(ecnFeedback.HasValue)
            .Write(cursor);

            largestAcknowledged.WriteVariable(cursor);
            delay.Write(cursor);

            var startPayloadOffset = cursor.AsOffset();

            cursor.EncodeVariable32(beforLargestAcknowledgedLength);

            var startRangesOffset = cursor.AsOffset();

            return(new WritingContext(cursor, ecnFeedback, startPayloadOffset, startRangesOffset));
        }
Example #2
0
 private AckFrame(AckDelay delay,
                  PacketNumber largestAcknowledged,
                  AckRanges ranges,
                  AckEcnCounts?ecnFeedback)
 {
     Delay = delay;
     LargestAcknowledged = largestAcknowledged;
     Ranges      = ranges;
     EcnFeedback = ecnFeedback;
 }
Example #3
0
        public static bool TryParse(MemoryCursor cursor, out AckFrame result)
        {
            result = new AckFrame();

            var type = FrameType.Peek(cursor);

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

            type.Slice(cursor);

            var largestAcknowledged = PacketNumber.ParseVariable(cursor);
            var delay       = AckDelay.Parse(cursor);
            var rangesCount = cursor.DecodeVariable32();
            var ranges      = SliceRanges(cursor, rangesCount + 1);
            var ecnFeedback = type.HasAckEcnFeedback ? AckEcnCounts.Parse(cursor) : new AckEcnCounts?();

            result = new AckFrame(delay, largestAcknowledged, ranges, ecnFeedback);

            return(true);
        }