Fixed bug in the calculation of payload site in publish decoder due to bad startPos recording
This commit is contained in:
@@ -18,9 +18,9 @@ class PublishDecoder extends DemuxDecoder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||||
LOG.debug("decode invoked with buffer " + in);
|
LOG.info("decode invoked with buffer " + in);
|
||||||
int startPos = in.readerIndex();
|
|
||||||
in.resetReaderIndex();
|
in.resetReaderIndex();
|
||||||
|
int startPos = in.readerIndex();
|
||||||
|
|
||||||
//Common decoding part
|
//Common decoding part
|
||||||
PublishMessage message = new PublishMessage();
|
PublishMessage message = new PublishMessage();
|
||||||
|
|||||||
@@ -123,6 +123,27 @@ public class PublishDecoderTest {
|
|||||||
assertNotNull(message);
|
assertNotNull(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBadClaimMoreData() throws Exception {
|
||||||
|
byte[] rawMessage = new byte[] {
|
||||||
|
0x30, 0x17, 0x00, 0x06, 0x2f, (byte)0x74, 0x6f, (byte)0x70, 0x69, 0x63, 0x54, 0x65, (byte)0x73, 0x74, 0x20, 0x6d,
|
||||||
|
(byte)0x79, 0x20, (byte)0x70, 0x61, (byte)0x79, 0x6c, 0x6f, 0x61, 0x64
|
||||||
|
};
|
||||||
|
|
||||||
|
ByteBuf msgBuf = Unpooled.buffer(25);
|
||||||
|
msgBuf.writeBytes(rawMessage);
|
||||||
|
msgBuf.readByte(); //to simulate the reading of messageType done by MQTTDecoder dispatcher
|
||||||
|
|
||||||
|
//Exercise
|
||||||
|
m_msgdec.decode(null, msgBuf, m_results);
|
||||||
|
|
||||||
|
assertFalse(m_results.isEmpty());
|
||||||
|
PublishMessage message = (PublishMessage)m_results.get(0);
|
||||||
|
assertNotNull(message);
|
||||||
|
assertEquals("/topic", message.getTopicName());
|
||||||
|
assertEquals("Test my payload", new String(message.getPayload()));
|
||||||
|
}
|
||||||
|
|
||||||
private void initHeader(ByteBuf buff) throws IllegalAccessException {
|
private void initHeader(ByteBuf buff) throws IllegalAccessException {
|
||||||
ByteBuf tmp = Unpooled.buffer(4).writeBytes(Utils.encodeString("Fake Topic"));
|
ByteBuf tmp = Unpooled.buffer(4).writeBytes(Utils.encodeString("Fake Topic"));
|
||||||
buff.clear().writeByte(AbstractMessage.PUBLISH << 4).writeBytes(Utils.encodeRemainingLength(tmp.readableBytes()));
|
buff.clear().writeByte(AbstractMessage.PUBLISH << 4).writeBytes(Utils.encodeRemainingLength(tmp.readableBytes()));
|
||||||
|
|||||||
Reference in New Issue
Block a user