Package io.netty.handler.codec.mqtt
Class MqttEncoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToMessageEncoder<MqttMessage>
-
- io.netty.handler.codec.mqtt.MqttEncoder
-
- All Implemented Interfaces:
ChannelHandler
,ChannelOutboundHandler
@Sharable public final class MqttEncoder extends MessageToMessageEncoder<MqttMessage>
Encodes Mqtt messages into bytes following the protocol specification v3.1 as described here MQTTV3.1
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description static MqttEncoder
INSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description private
MqttEncoder()
-
Method Summary
-
Methods inherited from class io.netty.handler.codec.MessageToMessageEncoder
acceptOutboundMessage, write
-
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, 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
exceptionCaught, handlerAdded, handlerRemoved
-
-
-
-
Field Detail
-
INSTANCE
public static final MqttEncoder INSTANCE
-
-
Method Detail
-
encode
protected void encode(ChannelHandlerContext ctx, MqttMessage msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
Description copied from class:MessageToMessageEncoder
Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.- Specified by:
encode
in classMessageToMessageEncoder<MqttMessage>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageEncoder
belongs tomsg
- the message to encode to an other oneout
- theList
into which the encoded msg should be added needs to do some kind of aggregation- Throws:
java.lang.Exception
- is thrown if an error occurs
-
doEncode
static ByteBuf doEncode(ByteBufAllocator byteBufAllocator, MqttMessage message)
This is the main encoding method. It's only visible for testing.- Parameters:
byteBufAllocator
- Allocates ByteBufmessage
- MQTT message to encode- Returns:
- ByteBuf with encoded bytes
-
encodeConnectMessage
private static ByteBuf encodeConnectMessage(ByteBufAllocator byteBufAllocator, MqttConnectMessage message)
-
getConnVariableHeaderFlag
private static int getConnVariableHeaderFlag(MqttConnectVariableHeader variableHeader)
-
encodeConnAckMessage
private static ByteBuf encodeConnAckMessage(ByteBufAllocator byteBufAllocator, MqttConnAckMessage message)
-
encodeSubscribeMessage
private static ByteBuf encodeSubscribeMessage(ByteBufAllocator byteBufAllocator, MqttSubscribeMessage message)
-
encodeUnsubscribeMessage
private static ByteBuf encodeUnsubscribeMessage(ByteBufAllocator byteBufAllocator, MqttUnsubscribeMessage message)
-
encodeSubAckMessage
private static ByteBuf encodeSubAckMessage(ByteBufAllocator byteBufAllocator, MqttSubAckMessage message)
-
encodePublishMessage
private static ByteBuf encodePublishMessage(ByteBufAllocator byteBufAllocator, MqttPublishMessage message)
-
encodeMessageWithOnlySingleByteFixedHeaderAndMessageId
private static ByteBuf encodeMessageWithOnlySingleByteFixedHeaderAndMessageId(ByteBufAllocator byteBufAllocator, MqttMessage message)
-
encodeMessageWithOnlySingleByteFixedHeader
private static ByteBuf encodeMessageWithOnlySingleByteFixedHeader(ByteBufAllocator byteBufAllocator, MqttMessage message)
-
getFixedHeaderByte1
private static int getFixedHeaderByte1(MqttFixedHeader header)
-
writeVariableLengthInt
private static void writeVariableLengthInt(ByteBuf buf, int num)
-
getVariableLengthInt
private static int getVariableLengthInt(int num)
-
encodeStringUtf8
private static byte[] encodeStringUtf8(java.lang.String s)
-
-