Added encode/decode for PingResp message
This commit is contained in:
@@ -27,6 +27,7 @@ public class MQTTDecoder extends ByteToMessageDecoder {
|
||||
m_decoderMap.put(AbstractMessage.UNSUBSCRIBE, new UnsubscribeDecoder());
|
||||
m_decoderMap.put(AbstractMessage.DISCONNECT, new DisconnectDecoder());
|
||||
m_decoderMap.put(AbstractMessage.PINGREQ, new PingReqDecoder());
|
||||
m_decoderMap.put(AbstractMessage.PINGRESP, new PingRespDecoder());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ public class MQTTEncoder extends MessageToByteEncoder<AbstractMessage> {
|
||||
m_encoderMap.put(AbstractMessage.UNSUBSCRIBE, new UnsubscribeEncoder());
|
||||
m_encoderMap.put(AbstractMessage.DISCONNECT, new DisconnectEncoder());
|
||||
m_encoderMap.put(AbstractMessage.PINGREQ, new PingReqEncoder());
|
||||
m_encoderMap.put(AbstractMessage.PINGRESP, new PingRespEncoder());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.dna.mqtt.moquette.parser.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.List;
|
||||
import org.dna.mqtt.moquette.proto.messages.PingRespMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
class PingRespDecoder extends DemuxDecoder {
|
||||
|
||||
@Override
|
||||
void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
//Common decoding part
|
||||
in.resetReaderIndex();
|
||||
PingRespMessage message = new PingRespMessage();
|
||||
if (!decodeCommonHeader(message, in)) {
|
||||
in.resetReaderIndex();
|
||||
return;
|
||||
}
|
||||
out.add(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.dna.mqtt.moquette.parser.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import org.dna.mqtt.moquette.proto.messages.AbstractMessage;
|
||||
import org.dna.mqtt.moquette.proto.messages.PingRespMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
class PingRespEncoder extends DemuxEncoder<PingRespMessage> {
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext chc, PingRespMessage msg, ByteBuf out) {
|
||||
out.writeByte(AbstractMessage.PINGRESP << 4).writeByte(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user