查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * 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 distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  
16  package io.netty.handler.codec.http2;
17  
18  import io.netty.util.internal.UnstableApi;
19  
20  /**
21   * All error codes identified by the HTTP/2 spec.
22   */
23  @UnstableApi
24  public enum Http2Error {
25      NO_ERROR(0x0),
26      PROTOCOL_ERROR(0x1),
27      INTERNAL_ERROR(0x2),
28      FLOW_CONTROL_ERROR(0x3),
29      SETTINGS_TIMEOUT(0x4),
30      STREAM_CLOSED(0x5),
31      FRAME_SIZE_ERROR(0x6),
32      REFUSED_STREAM(0x7),
33      CANCEL(0x8),
34      COMPRESSION_ERROR(0x9),
35      CONNECT_ERROR(0xA),
36      ENHANCE_YOUR_CALM(0xB),
37      INADEQUATE_SECURITY(0xC),
38      HTTP_1_1_REQUIRED(0xD);
39  
40      private final long code;
41      private static final Http2Error[] INT_TO_ENUM_MAP;
42      static {
43          Http2Error[] errors = values();
44          Http2Error[] map = new Http2Error[errors.length];
45          for (Http2Error error : errors) {
46              map[(int) error.code()] = error;
47          }
48          INT_TO_ENUM_MAP = map;
49      }
50  
51      Http2Error(long code) {
52          this.code = code;
53      }
54  
55      /**
56       * Gets the code for this error used on the wire.
57       */
58      public long code() {
59          return code;
60      }
61  
62      public static Http2Error valueOf(long value) {
63          return value >= INT_TO_ENUM_MAP.length || value < 0 ? null : INT_TO_ENUM_MAP[(int) value];
64      }
65  }