View Javadoc
1   /*
2    * Copyright 2014 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    *   http://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  
17  package io.netty.handler.codec.mqtt;
18  
19  import java.util.Collections;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  /**
24   * Return Code of {@link io.netty.handler.codec.mqtt.MqttConnAckMessage}
25   */
26  public enum MqttConnectReturnCode {
27      CONNECTION_ACCEPTED((byte) 0x00),
28      CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION((byte) 0X01),
29      CONNECTION_REFUSED_IDENTIFIER_REJECTED((byte) 0x02),
30      CONNECTION_REFUSED_SERVER_UNAVAILABLE((byte) 0x03),
31      CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD((byte) 0x04),
32      CONNECTION_REFUSED_NOT_AUTHORIZED((byte) 0x05);
33  
34      private  static final Map<Byte, MqttConnectReturnCode> valueToCodeMap;
35  
36      static {
37          final Map<Byte, MqttConnectReturnCode> valueMap = new HashMap<Byte, MqttConnectReturnCode>();
38          for (MqttConnectReturnCode code: values()) {
39              valueMap.put(code.byteValue, code);
40          }
41          valueToCodeMap = Collections.unmodifiableMap(valueMap);
42      }
43  
44      private final byte byteValue;
45  
46      MqttConnectReturnCode(byte byteValue) {
47          this.byteValue = byteValue;
48      }
49  
50      public byte byteValue() {
51          return byteValue;
52      }
53  
54      public static MqttConnectReturnCode valueOf(byte b) {
55          if (valueToCodeMap.containsKey(b)) {
56              return valueToCodeMap.get(b);
57          }
58          throw new IllegalArgumentException("unknown connect return code: " + (b & 0xFF));
59      }
60  }