View Javadoc
1   /*
2    * Copyright 2020 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.quic;
17  
18  /**
19   * The type of the
20   * <a href="https://quicwg.org/base-drafts/rfc9000.html#name-packets-and-frames">QUIC packet</a>.
21   */
22  public enum QuicPacketType {
23      /**
24       * Initial packet.
25       */
26      INITIAL,
27  
28      /**
29       * Retry packet.
30       */
31      RETRY,
32  
33      /**
34       * Handshake packet.
35       */
36      HANDSHAKE,
37  
38      /**
39       * 0-RTT packet.
40       */
41      ZERO_RTT,
42  
43      /**
44       * 1-RTT short header packet.
45       */
46      SHORT,
47  
48      /**
49       * Version negotiation packet.
50       */
51      VERSION_NEGOTIATION;
52  
53      /**
54       * Return the {@link QuicPacketType} for the given byte.
55       *
56       * @param type  the byte that represent the type.
57       * @return      the {@link QuicPacketType}.
58       */
59      static QuicPacketType of(byte type) {
60          switch(type) {
61              case 1:
62                  return INITIAL;
63              case 2:
64                  return RETRY;
65              case 3:
66                  return HANDSHAKE;
67              case 4:
68                  return ZERO_RTT;
69              case 5:
70                  return SHORT;
71              case 6:
72                  return VERSION_NEGOTIATION;
73              default:
74                  throw new IllegalArgumentException("Unknown QUIC packet type: " + type);
75          }
76      }
77  }