Fixing QOSType encoding and decoding of FAILURE qos (0x80). This was causing bug with decoding a SubAck with failure qos type. See Appendix B: MQTT-3.9.3-2
This commit is contained in:
@@ -73,7 +73,11 @@ abstract class DemuxDecoder {
|
||||
|
||||
message.setMessageType(messageType);
|
||||
message.setDupFlag(dupFlag);
|
||||
message.setQos(AbstractMessage.QOSType.values()[qosLevel]);
|
||||
try {
|
||||
message.setQos(AbstractMessage.QOSType.valueOf(qosLevel));
|
||||
} catch(IllegalArgumentException e) {
|
||||
throw new CorruptedFrameException(String.format("Received an invalid QOS: %s", e.getMessage()), e);
|
||||
}
|
||||
message.setRetainFlag(retainFlag);
|
||||
message.setRemainingLength(remainingLength);
|
||||
return true;
|
||||
|
||||
@@ -49,7 +49,7 @@ class SubAckDecoder extends DemuxDecoder {
|
||||
}
|
||||
for (int i = 0; i < remainingLength; i++) {
|
||||
byte qos = in.readByte();
|
||||
message.addType(AbstractMessage.QOSType.values()[qos]);
|
||||
message.addType(AbstractMessage.QOSType.valueOf(qos));
|
||||
}
|
||||
|
||||
out.add(message);
|
||||
|
||||
@@ -40,8 +40,7 @@ class SubAckEncoder extends DemuxEncoder<SubAckMessage> {
|
||||
buff.writeBytes(Utils.encodeRemainingLength(variableHeaderSize));
|
||||
buff.writeShort(message.getMessageID());
|
||||
for (QOSType c : message.types()) {
|
||||
int qosValue = (c == QOSType.FAILURE) ? qosValue = 0x80 : c.ordinal();
|
||||
buff.writeByte(qosValue);
|
||||
buff.writeByte(c.byteValue());
|
||||
}
|
||||
|
||||
out.writeBytes(buff);
|
||||
|
||||
@@ -184,7 +184,7 @@ public class Utils {
|
||||
flags |= 0x01;
|
||||
}
|
||||
|
||||
flags |= ((message.getQos().ordinal() & 0x03) << 1);
|
||||
flags |= ((message.getQos().byteValue() & 0x03) << 1);
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user