Package org.bluezoo.gumdrop.mqtt.codec
Class MQTTPacketEncoder
java.lang.Object
org.bluezoo.gumdrop.mqtt.codec.MQTTPacketEncoder
Encodes MQTT control packets to wire format.
Each encode* method returns a ByteBuffer in read
mode containing the complete packet ready for transmission.
All methods use flat parameter signatures — no packet objects
are required except for encodeConnect(ConnectPacket) which
retains the packet object due to its 12+ fields.
- Author:
- Chris Burdess
-
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBufferencodeAuth(int reasonCode, MQTTProperties props) static ByteBufferencodeConnAck(boolean sessionPresent, int returnCode, MQTTProperties props, MQTTVersion version) static ByteBufferencodeConnect(ConnectPacket packet) static ByteBufferencodeDisconnect(int reasonCode, MQTTProperties props, MQTTVersion version) static ByteBufferstatic ByteBufferstatic ByteBufferencodePubAck(int packetId, int reasonCode, MQTTProperties props, MQTTVersion version) static ByteBufferencodePubComp(int packetId, int reasonCode, MQTTProperties props, MQTTVersion version) static ByteBufferencodePublish(String topic, int qos, boolean dup, boolean retain, int packetId, byte[] payload, MQTTProperties props, MQTTVersion version) static ByteBufferencodePublishHeader(String topic, int qos, boolean dup, boolean retain, int packetId, long payloadSize, MQTTProperties props, MQTTVersion version) Encodes just the PUBLISH fixed header and variable header, without the payload.static ByteBufferencodePubRec(int packetId, int reasonCode, MQTTProperties props, MQTTVersion version) static ByteBufferencodePubRel(int packetId, int reasonCode, MQTTProperties props, MQTTVersion version) static ByteBufferencodeSubAck(int packetId, int[] returnCodes, MQTTProperties props, MQTTVersion version) static ByteBufferencodeSubscribe(int packetId, String[] topicFilters, int[] qosLevels, MQTTProperties props, MQTTVersion version) static ByteBufferencodeUnsubAck(int packetId, int[] reasonCodes, MQTTProperties props, MQTTVersion version) static ByteBufferencodeUnsubscribe(int packetId, String[] topicFilters, MQTTProperties props, MQTTVersion version)
-
Method Details
-
encodeConnect
-
encodeConnAck
public static ByteBuffer encodeConnAck(boolean sessionPresent, int returnCode, MQTTProperties props, MQTTVersion version) -
encodePublish
public static ByteBuffer encodePublish(String topic, int qos, boolean dup, boolean retain, int packetId, byte[] payload, MQTTProperties props, MQTTVersion version) -
encodePublishHeader
public static ByteBuffer encodePublishHeader(String topic, int qos, boolean dup, boolean retain, int packetId, long payloadSize, MQTTProperties props, MQTTVersion version) Encodes just the PUBLISH fixed header and variable header, without the payload. Used for streaming delivery where the payload is sent separately via chunkedEndpoint.send(java.nio.ByteBuffer)calls from anReadableByteChannel.The remaining length in the fixed header includes the payload size, so the receiver can determine the frame boundary.
- Parameters:
topic- the topic nameqos- the QoS level (0, 1, or 2)dup- the DUP flagretain- the RETAIN flagpacketId- the packet identifier (0 for QoS 0)payloadSize- the payload size in bytesprops- MQTT 5.0 propertiesversion- the MQTT version- Returns:
- a ByteBuffer containing the fixed + variable header
-
encodePubAck
public static ByteBuffer encodePubAck(int packetId, int reasonCode, MQTTProperties props, MQTTVersion version) -
encodePubRec
public static ByteBuffer encodePubRec(int packetId, int reasonCode, MQTTProperties props, MQTTVersion version) -
encodePubRel
public static ByteBuffer encodePubRel(int packetId, int reasonCode, MQTTProperties props, MQTTVersion version) -
encodePubComp
public static ByteBuffer encodePubComp(int packetId, int reasonCode, MQTTProperties props, MQTTVersion version) -
encodeSubscribe
public static ByteBuffer encodeSubscribe(int packetId, String[] topicFilters, int[] qosLevels, MQTTProperties props, MQTTVersion version) -
encodeSubAck
public static ByteBuffer encodeSubAck(int packetId, int[] returnCodes, MQTTProperties props, MQTTVersion version) -
encodeUnsubscribe
public static ByteBuffer encodeUnsubscribe(int packetId, String[] topicFilters, MQTTProperties props, MQTTVersion version) -
encodeUnsubAck
public static ByteBuffer encodeUnsubAck(int packetId, int[] reasonCodes, MQTTProperties props, MQTTVersion version) -
encodePingReq
-
encodePingResp
-
encodeDisconnect
public static ByteBuffer encodeDisconnect(int reasonCode, MQTTProperties props, MQTTVersion version) -
encodeAuth
-