Bug fix and test to check correct encoding of retain flag
This commit is contained in:
@@ -132,10 +132,13 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static byte encodeFlags(AbstractMessage message) {
|
static byte encodeFlags(AbstractMessage message) {
|
||||||
byte flags = 0;
|
byte flags = 0;
|
||||||
if (message.isDupFlag()) {
|
if (message.isDupFlag()) {
|
||||||
flags |= 0x08;
|
flags |= 0x08;
|
||||||
}
|
}
|
||||||
|
if (message.isRetainFlag()) {
|
||||||
|
flags |= 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
flags |= ((message.getQos().ordinal() & 0x03) << 1);
|
flags |= ((message.getQos().ordinal() & 0x03) << 1);
|
||||||
return flags;
|
return flags;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.dna.mqtt.moquette.proto;
|
package org.dna.mqtt.moquette.proto;
|
||||||
|
|
||||||
import org.dna.mqtt.moquette.proto.Utils;
|
|
||||||
import org.dna.mqtt.moquette.proto.messages.AbstractMessage;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import org.apache.mina.core.buffer.IoBuffer;
|
import org.apache.mina.core.buffer.IoBuffer;
|
||||||
import org.apache.mina.core.filterchain.IoFilter.NextFilter;
|
import org.apache.mina.core.filterchain.IoFilter.NextFilter;
|
||||||
@@ -9,6 +7,7 @@ import org.apache.mina.core.future.WriteFuture;
|
|||||||
import org.apache.mina.core.session.IoSession;
|
import org.apache.mina.core.session.IoSession;
|
||||||
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
|
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
|
||||||
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
|
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
|
||||||
|
import org.dna.mqtt.moquette.proto.messages.AbstractMessage;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.dna.mqtt.moquette.proto;
|
||||||
|
|
||||||
|
import org.dna.mqtt.moquette.proto.messages.AbstractMessage;
|
||||||
|
import org.dna.mqtt.moquette.proto.messages.UnsubscribeMessage;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author andrea
|
||||||
|
*/
|
||||||
|
public class UtilsTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncodeFlags() {
|
||||||
|
UnsubscribeMessage msg = new UnsubscribeMessage();
|
||||||
|
msg.setRetainFlag(true);
|
||||||
|
msg.setQos(AbstractMessage.QOSType.MOST_ONE);
|
||||||
|
|
||||||
|
//Exercise
|
||||||
|
assertEquals(1, Utils.encodeFlags(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user