增加协议版本,新版本添加对gzip的支持

This commit is contained in:
heavyrain.lee
2019-05-27 10:06:22 +08:00
parent d3aa68df05
commit b4b70ca7e5
6 changed files with 32 additions and 10 deletions
@@ -43,7 +43,7 @@ final class MqttCodecUtil {
return clientId != null && clientId.length() >= MIN_CLIENT_ID_LENGTH &&
clientId.length() <= MAX_CLIENT_ID_LENGTH;
}
if (mqttVersion == MqttVersion.MQTT_3_1_1) {
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.Wildfire_1) {
// In 3.1.3.1 Client Identifier of MQTT 3.1.1 specification, The Server MAY allow ClientId’s
// that contain more than 23 encoded bytes. And, The Server MAY allow zero-length ClientId.
return clientId != null;
@@ -223,7 +223,7 @@ public final class MqttDecoder extends ReplayingDecoder<DecoderState> {
final int willQos = (b1 & 0x18) >> 3;
final boolean willFlag = (b1 & 0x04) == 0x04;
final boolean cleanSession = (b1 & 0x02) == 0x02;
if (mqttVersion == MqttVersion.MQTT_3_1_1) {
if (mqttVersion == MqttVersion.MQTT_3_1_1 || mqttVersion == MqttVersion.Wildfire_1) {
final boolean zeroReservedFlag = (b1 & 0x01) == 0x0;
if (!zeroReservedFlag) {
// MQTT v3.1.1: The Server MUST validate that the reserved flag in the CONNECT Control Packet is
@@ -24,7 +24,8 @@ import io.netty.util.internal.ObjectUtil;
*/
public enum MqttVersion {
MQTT_3_1("MQIsdp", (byte) 3),
MQTT_3_1_1("MQTT", (byte) 4);
MQTT_3_1_1("MQTT", (byte) 4),
Wildfire_1("MQTT", (byte) 5);
private final String name;
private final byte level;
@@ -52,11 +53,19 @@ public enum MqttVersion {
if (mv.level == protocolLevel) {
return mv;
} else {
throw new MqttUnacceptableProtocolVersionException(protocolName + " and " +
protocolLevel + " are not match");
continue;
}
}
}
throw new MqttUnacceptableProtocolVersionException(protocolName + "is unknown protocol name");
}
public static MqttVersion fromProtocolLevel(int protocolLevel) {
for (MqttVersion mv : values()) {
if (mv.level == (byte )protocolLevel) {
return mv;
}
}
throw new MqttUnacceptableProtocolVersionException(protocolLevel + "is unknown protocol level");
}
}