Package io.netty.handler.codec.mqtt
Class MqttDecoder
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum
States of the decoder.private static final class
Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.Cumulator
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private final int
private final int
private MqttFixedHeader
private Object
Fields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR
-
Constructor Summary
ConstructorsConstructorDescriptionMqttDecoder
(int maxBytesInMessage) MqttDecoder
(int maxBytesInMessage, int maxClientIdLength) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
decode
(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) Decode the from oneByteBuf
to an other.private static byte[]
decodeByteArray
(ByteBuf buffer) private MqttConnAckVariableHeader
decodeConnAckVariableHeader
(ChannelHandlerContext ctx, ByteBuf buffer) private MqttConnectPayload
decodeConnectionPayload
(ByteBuf buffer, int maxClientIdLength, MqttConnectVariableHeader mqttConnectVariableHeader) private MqttConnectVariableHeader
decodeConnectionVariableHeader
(ChannelHandlerContext ctx, ByteBuf buffer) private static MqttFixedHeader
decodeFixedHeader
(ChannelHandlerContext ctx, ByteBuf buffer) Decodes the fixed header.private static int
decodeMessageId
(ByteBuf buffer) private static int
decodeMsbLsb
(ByteBuf buffer) numberOfBytesConsumed = 2.private Object
decodePayload
(ChannelHandlerContext ctx, ByteBuf buffer, MqttMessageType messageType, int maxClientIdLength, Object variableHeader) Decodes the payload.private static MqttDecoder.Result
<MqttProperties> decodeProperties
(ByteBuf buffer) private ByteBuf
decodePublishPayload
(ByteBuf buffer) private MqttPublishVariableHeader
decodePublishVariableHeader
(ChannelHandlerContext ctx, ByteBuf buffer, MqttFixedHeader mqttFixedHeader) decodePubReplyMessage
(ByteBuf buffer) private static MqttDecoder.Result
<String> decodeString
(ByteBuf buffer) private static MqttDecoder.Result
<String> decodeString
(ByteBuf buffer, int minBytes, int maxBytes) private MqttSubAckPayload
decodeSubackPayload
(ByteBuf buffer) private MqttSubscribePayload
decodeSubscribePayload
(ByteBuf buffer) private MqttUnsubAckPayload
decodeUnsubAckPayload
(ChannelHandlerContext ctx, ByteBuf buffer) private MqttUnsubscribePayload
decodeUnsubscribePayload
(ByteBuf buffer) private static long
decodeVariableByteInteger
(ByteBuf buffer) See 1.5.5 Variable Byte Integer section of MQTT 5.0 specification for encoding/decoding rulesprivate Object
decodeVariableHeader
(ChannelHandlerContext ctx, ByteBuf buffer, MqttFixedHeader mqttFixedHeader) Decodes the variable header (if any)private MqttMessage
invalidMessage
(Throwable cause) private static long
packInts
(int a, int b) private static int
unpackA
(long ints) private static int
unpackB
(long ints) private void
validateNoBytesRemain
(int numberOfBytesConsumed) Methods inherited from class io.netty.handler.codec.ReplayingDecoder
callDecode, checkpoint, checkpoint, state, state
Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded
-
Field Details
-
mqttFixedHeader
-
variableHeader
-
bytesRemainingInVariablePart
private int bytesRemainingInVariablePart -
maxBytesInMessage
private final int maxBytesInMessage -
maxClientIdLength
private final int maxClientIdLength
-
-
Constructor Details
-
MqttDecoder
public MqttDecoder() -
MqttDecoder
public MqttDecoder(int maxBytesInMessage) -
MqttDecoder
public MqttDecoder(int maxBytesInMessage, int maxClientIdLength)
-
-
Method Details
-
decode
Description copied from class:ByteToMessageDecoder
Decode the from oneByteBuf
to an other. This method will be called till either the inputByteBuf
has nothing to read when return from this method or till nothing was read from the inputByteBuf
.- Specified by:
decode
in classByteToMessageDecoder
- Parameters:
ctx
- theChannelHandlerContext
which thisByteToMessageDecoder
belongs tobuffer
- theByteBuf
from which to read dataout
- theList
to which decoded messages should be added- Throws:
Exception
- is thrown if an error occurs
-
invalidMessage
-
decodeFixedHeader
Decodes the fixed header. It's one byte for the flags and then variable bytes for the remaining length.- Parameters:
buffer
- the buffer to decode from- Returns:
- the fixed header
-
decodeVariableHeader
private Object decodeVariableHeader(ChannelHandlerContext ctx, ByteBuf buffer, MqttFixedHeader mqttFixedHeader) Decodes the variable header (if any)- Parameters:
buffer
- the buffer to decode frommqttFixedHeader
- MqttFixedHeader of the same message- Returns:
- the variable header
-
decodeConnectionVariableHeader
private MqttConnectVariableHeader decodeConnectionVariableHeader(ChannelHandlerContext ctx, ByteBuf buffer) -
decodeConnAckVariableHeader
private MqttConnAckVariableHeader decodeConnAckVariableHeader(ChannelHandlerContext ctx, ByteBuf buffer) -
decodeMessageIdAndPropertiesVariableHeader
private MqttMessageIdAndPropertiesVariableHeader decodeMessageIdAndPropertiesVariableHeader(ChannelHandlerContext ctx, ByteBuf buffer) -
decodePubReplyMessage
-
decodeReasonCodeAndPropertiesVariableHeader
private MqttReasonCodeAndPropertiesVariableHeader decodeReasonCodeAndPropertiesVariableHeader(ByteBuf buffer) -
decodePublishVariableHeader
private MqttPublishVariableHeader decodePublishVariableHeader(ChannelHandlerContext ctx, ByteBuf buffer, MqttFixedHeader mqttFixedHeader) -
decodeMessageId
- Returns:
- messageId with numberOfBytesConsumed is 2
-
decodePayload
private Object decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, MqttMessageType messageType, int maxClientIdLength, Object variableHeader) Decodes the payload.- Parameters:
buffer
- the buffer to decode frommessageType
- type of the message being decodedvariableHeader
- variable header of the same message- Returns:
- the payload
-
decodeConnectionPayload
private MqttConnectPayload decodeConnectionPayload(ByteBuf buffer, int maxClientIdLength, MqttConnectVariableHeader mqttConnectVariableHeader) -
decodeSubscribePayload
-
decodeSubackPayload
-
decodeUnsubAckPayload
-
decodeUnsubscribePayload
-
decodePublishPayload
-
validateNoBytesRemain
private void validateNoBytesRemain(int numberOfBytesConsumed) -
decodeString
-
decodeString
-
decodeByteArray
- Returns:
- the decoded byte[], numberOfBytesConsumed = byte[].length + 2
-
packInts
private static long packInts(int a, int b) -
unpackA
private static int unpackA(long ints) -
unpackB
private static int unpackB(long ints) -
decodeMsbLsb
numberOfBytesConsumed = 2. return decoded result. -
decodeVariableByteInteger
See 1.5.5 Variable Byte Integer section of MQTT 5.0 specification for encoding/decoding rules- Parameters:
buffer
- the buffer to decode from- Returns:
- result pack with a = decoded integer, b = numberOfBytesConsumed. Need to unpack to read them.
- Throws:
DecoderException
- if bad MQTT protocol limits Remaining Length
-
decodeProperties
-