@Test public void testBugBadRemainingCalculation() throws Exception { byte[] overallMessage = new byte[] {(byte)0x90, 0x03, 0x00, 0x0A, 0x01}; m_buff = IoBuffer.allocate(overallMessage.length).setAutoExpand(true); m_buff.put(overallMessage); m_buff.flip(); MessageDecoderResult res = m_msgdec.decode(null, m_buff, m_mockProtoDecoder); assertNotNull(m_mockProtoDecoder.getMessage()); assertEquals(MessageDecoder.OK, res); SubAckMessage message = (SubAckMessage) m_mockProtoDecoder.getMessage(); assertEquals(0x0A, message.getMessageID().intValue()); assertEquals(1, message.types().size()); assertEquals(AbstractMessage.QOSType.LEAST_ONE, message.types().get(0)); }
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);  }