Beispiel #1
0
 public static void AssertFrameType(Http3FrameType actual, Http3FrameType expected)
 {
     if (actual != expected)
     {
         throw new InvalidOperationException($"Expected {expected} frame. Got {actual}.");
     }
 }
Beispiel #2
0
 public static string ToFormattedType(Http3FrameType type)
 {
     return(type switch
     {
         Http3FrameType.Data => "DATA",
         Http3FrameType.Headers => "HEADERS",
         Http3FrameType.CancelPush => "CANCEL_PUSH",
         Http3FrameType.Settings => "SETTINGS",
         Http3FrameType.PushPromise => "PUSH_PROMISE",
         Http3FrameType.GoAway => "GO_AWAY",
         Http3FrameType.MaxPushId => "MAX_PUSH_ID",
         _ => type.ToString()
     });
Beispiel #3
0
        //  0                   1                   2                   3
        //  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        // |                           Type (i)                          ...
        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        // |                          Length (i)                         ...
        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        // |                       Frame Payload (*)                     ...
        // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        public static bool TryWriteFrameEnvelope(Http3FrameType frameType, long payloadLength, Span <byte> buffer, out int bytesWritten)
        {
            Debug.Assert(VariableLengthIntegerHelper.GetByteCount((long)frameType) == 1, $"{nameof(TryWriteFrameEnvelope)} assumes {nameof(frameType)} will fit within a single byte varint.");

            if (buffer.Length != 0)
            {
                buffer[0] = (byte)frameType;
                buffer    = buffer.Slice(1);

                if (VariableLengthIntegerHelper.TryWrite(buffer, payloadLength, out int payloadLengthEncodedLength))
                {
                    bytesWritten = payloadLengthEncodedLength + 1;
                    return(true);
                }
            }

            bytesWritten = 0;
            return(false);
        }