@Test public void testBadQos() throws Exception { initHeaderQos(m_buff, 0xAABB, QOSType.LEAST_ONE, QOSType.MOST_ONE, QOSType.MOST_ONE); m_buff.flip(); MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder); assertEquals(MessageDecoderResult.OK, res); assertEquals(0xAABB, m_mockProtoDecoder.getMessage().getMessageID().intValue()); List<QOSType> qoses = m_mockProtoDecoder.getMessage().types(); assertEquals(3, qoses.size()); assertEquals(QOSType.LEAST_ONE, qoses.get(0)); assertEquals(QOSType.MOST_ONE, qoses.get(1)); assertEquals(QOSType.MOST_ONE, qoses.get(2)); assertEquals(AbstractMessage.SUBACK, m_mockProtoDecoder.getMessage().getMessageType()); }
public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { SubAckMessage message = new SubAckMessage(); if (decodeCommonHeader(message, in) == NEED_DATA) { return NEED_DATA; } int remainingLength = message.getRemainingLength(); message.setMessageID(Utils.readWord(in)); remainingLength -= 2; if (in.remaining() < remainingLength ) { return NEED_DATA; } for (int i = 0; i < remainingLength; i++) { byte qos = in.get(); message.addType(QOSType.values()[qos]); } out.write(message); return OK; }
SubAckDecoder extends MqttDecoder { public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { SubAckMessage message = new SubAckMessage(); if (decodeCommonHeader(message, in) == NEED_DATA) { return NEED_DATA; } int remainingLength = message.getRemainingLength(); message.setMessageID(Utils.readWord(in)); remainingLength -= 2; if (in.remaining() < remainingLength ) { return NEED_DATA; } for (int i = 0; i < remainingLength; i++) { byte qos = in.get(); message.addType(QOSType.values()[qos]); } out.write(message); return OK; } }
SubAckDecoder extends MqttDecoder { public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { SubAckMessage message = new SubAckMessage(); if (decodeCommonHeader(message, in) == NEED_DATA) { return NEED_DATA; } int remainingLength = message.getRemainingLength(); message.setMessageID(Utils.readWord(in)); remainingLength -= 2; if (in.remaining() < remainingLength ) { return NEED_DATA; } for (int i = 0; i < remainingLength; i++) { byte qos = in.get(); message.addType(QOSType.values()[qos]); } out.write(message); return OK; }  }
SubAckDecoder extends MqttDecoder { public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { SubAckMessage message = new SubAckMessage(); if (decodeCommonHeader(message, in) == NEED_DATA) { return NEED_DATA; } int remainingLength = message.getRemainingLength(); message.setMessageID(Utils.readWord(in)); remainingLength -= 2; if (in.remaining() < remainingLength ) { return NEED_DATA; } for (int i = 0; i < remainingLength; i++) { byte qos = in.get(); message.addType(QOSType.values()[qos]); } out.write(message); return OK; }  MessageDecoderResult decodable(IoSession session, IoBuffer in); MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out); }
SubAckDecoder extends MqttDecoder { public MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { SubAckMessage message = new SubAckMessage(); if (decodeCommonHeader(message, in) == NEED_DATA) { return NEED_DATA; } int remainingLength = message.getRemainingLength(); message.setMessageID(Utils.readWord(in)); remainingLength -= 2; if (in.remaining() < remainingLength ) { return NEED_DATA; } for (int i = 0; i < remainingLength; i++) { byte qos = in.get(); message.addType(QOSType.values()[qos]); } out.write(message); return OK; }  MessageDecoderResult decodable(IoSession session, IoBuffer in); MessageDecoderResult decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out);  }