Motivation:
Since 3.1.1 mqtt protocol version SUBACK message can now indicate the failure in payload. Modification: Do not erase failure payload in for SUBACK message. Result: Fixes #7665
This commit is contained in:
parent
46e66b45bd
commit
7bbb4ef8a2
@ -392,7 +392,10 @@ public final class MqttDecoder extends ReplayingDecoder<DecoderState> {
|
||||
final List<Integer> grantedQos = new ArrayList<Integer>();
|
||||
int numberOfBytesConsumed = 0;
|
||||
while (numberOfBytesConsumed < bytesRemainingInVariablePart) {
|
||||
int qos = buffer.readUnsignedByte() & 0x03;
|
||||
int qos = buffer.readUnsignedByte();
|
||||
if (qos != MqttQoS.FAILURE.value()) {
|
||||
qos &= 0x03;
|
||||
}
|
||||
numberOfBytesConsumed++;
|
||||
grantedQos.add(qos);
|
||||
}
|
||||
|
@ -214,6 +214,30 @@ public class MqttCodecTest {
|
||||
validateSubAckPayload(message.payload(), decodedMessage.payload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubAckMessageWithFailureInPayload() throws Exception {
|
||||
MqttFixedHeader mqttFixedHeader =
|
||||
new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
|
||||
MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(12345);
|
||||
MqttSubAckPayload mqttSubAckPayload = new MqttSubAckPayload(MqttQoS.FAILURE.value());
|
||||
MqttSubAckMessage message =
|
||||
new MqttSubAckMessage(mqttFixedHeader, mqttMessageIdVariableHeader, mqttSubAckPayload);
|
||||
|
||||
ByteBuf byteBuf = MqttEncoder.doEncode(ALLOCATOR, message);
|
||||
|
||||
List<Object> out = new LinkedList<Object>();
|
||||
mqttDecoder.decode(ctx, byteBuf, out);
|
||||
|
||||
assertEquals("Expected one object but got " + out.size(), 1, out.size());
|
||||
|
||||
MqttSubAckMessage decodedMessage = (MqttSubAckMessage) out.get(0);
|
||||
validateFixedHeaders(message.fixedHeader(), decodedMessage.fixedHeader());
|
||||
validateMessageIdVariableHeader(message.variableHeader(), decodedMessage.variableHeader());
|
||||
validateSubAckPayload(message.payload(), decodedMessage.payload());
|
||||
assertEquals(1, decodedMessage.payload().grantedQoSLevels().size());
|
||||
assertEquals(MqttQoS.FAILURE, MqttQoS.valueOf(decodedMessage.payload().grantedQoSLevels().get(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnSubscribeMessage() throws Exception {
|
||||
final MqttUnsubscribeMessage message = createUnsubscribeMessage();
|
||||
|
Loading…
Reference in New Issue
Block a user