org.eclipse.paho.client.mqttv3.internal.wire
Class MqttWireMessage

java.lang.Object
  extended by org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage
Direct Known Subclasses:
MqttAck, MqttConnect, MqttDisconnect, MqttPersistableWireMessage, MqttPingReq, MqttSubscribe, MqttUnsubscribe

public abstract class MqttWireMessage
extends Object

An on-the-wire representation of an MQTT message.


Field Summary
protected  boolean duplicate
           
static byte MESSAGE_TYPE_CONNACK
           
static byte MESSAGE_TYPE_CONNECT
           
static byte MESSAGE_TYPE_DISCONNECT
           
static byte MESSAGE_TYPE_PINGREQ
           
static byte MESSAGE_TYPE_PINGRESP
           
static byte MESSAGE_TYPE_PUBACK
           
static byte MESSAGE_TYPE_PUBCOMP
           
static byte MESSAGE_TYPE_PUBLISH
           
static byte MESSAGE_TYPE_PUBREC
           
static byte MESSAGE_TYPE_PUBREL
           
static byte MESSAGE_TYPE_SUBACK
           
static byte MESSAGE_TYPE_SUBSCRIBE
           
static byte MESSAGE_TYPE_UNSUBACK
           
static byte MESSAGE_TYPE_UNSUBSCRIBE
           
protected  int msgId
          The MQTT message ID
protected static String STRING_ENCODING
           
 
Constructor Summary
MqttWireMessage(byte type)
           
 
Method Summary
static MqttWireMessage createWireMessage(byte[] bytes)
           
static MqttWireMessage createWireMessage(MqttPersistable data)
           
protected  String decodeUTF8(DataInputStream input)
          Decodes a UTF-8 string from the DataInputStream provided.
protected static byte[] encodeMBI(long number)
           
protected  byte[] encodeMessageId()
           
protected  void encodeUTF8(DataOutputStream dos, String stringToEncode)
          Encodes a String given into UTF-8, before writing this to the DataOutputStream the length of the encoded string is encoded into two bytes and then written to the DataOutputStream.
 byte[] getHeader()
           
 String getKey()
          Returns a key associated with the message.
 int getMessageId()
          Returns the MQTT message ID.
protected abstract  byte getMessageInfo()
          Sub-classes should override this to encode the message info.
 byte[] getPayload()
          Sub-classes should override this method to supply the payload bytes.
 byte getType()
          Returns the type of the message.
protected abstract  byte[] getVariableHeader()
           
 boolean isMessageIdRequired()
          Returns whether or not this message needs to include a message ID.
 boolean isRetryable()
           
protected static MultiByteInteger readMBI(DataInputStream in)
          Decodes an MQTT Multi-Byte Integer from the given stream.
 void setDuplicate(boolean duplicate)
           
 void setMessageId(int msgId)
          Sets the MQTT message ID.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STRING_ENCODING

protected static final String STRING_ENCODING
See Also:
Constant Field Values

MESSAGE_TYPE_CONNECT

public static final byte MESSAGE_TYPE_CONNECT
See Also:
Constant Field Values

MESSAGE_TYPE_CONNACK

public static final byte MESSAGE_TYPE_CONNACK
See Also:
Constant Field Values

MESSAGE_TYPE_PUBLISH

public static final byte MESSAGE_TYPE_PUBLISH
See Also:
Constant Field Values

MESSAGE_TYPE_PUBACK

public static final byte MESSAGE_TYPE_PUBACK
See Also:
Constant Field Values

MESSAGE_TYPE_PUBREC

public static final byte MESSAGE_TYPE_PUBREC
See Also:
Constant Field Values

MESSAGE_TYPE_PUBREL

public static final byte MESSAGE_TYPE_PUBREL
See Also:
Constant Field Values

MESSAGE_TYPE_PUBCOMP

public static final byte MESSAGE_TYPE_PUBCOMP
See Also:
Constant Field Values

MESSAGE_TYPE_SUBSCRIBE

public static final byte MESSAGE_TYPE_SUBSCRIBE
See Also:
Constant Field Values

MESSAGE_TYPE_SUBACK

public static final byte MESSAGE_TYPE_SUBACK
See Also:
Constant Field Values

MESSAGE_TYPE_UNSUBSCRIBE

public static final byte MESSAGE_TYPE_UNSUBSCRIBE
See Also:
Constant Field Values

MESSAGE_TYPE_UNSUBACK

public static final byte MESSAGE_TYPE_UNSUBACK
See Also:
Constant Field Values

MESSAGE_TYPE_PINGREQ

public static final byte MESSAGE_TYPE_PINGREQ
See Also:
Constant Field Values

MESSAGE_TYPE_PINGRESP

public static final byte MESSAGE_TYPE_PINGRESP
See Also:
Constant Field Values

MESSAGE_TYPE_DISCONNECT

public static final byte MESSAGE_TYPE_DISCONNECT
See Also:
Constant Field Values

msgId

protected int msgId
The MQTT message ID


duplicate

protected boolean duplicate
Constructor Detail

MqttWireMessage

public MqttWireMessage(byte type)
Method Detail

getMessageInfo

protected abstract byte getMessageInfo()
Sub-classes should override this to encode the message info. Only the least-significant four bits will be used.


getPayload

public byte[] getPayload()
                  throws MqttException
Sub-classes should override this method to supply the payload bytes.

Throws:
MqttException

getType

public byte getType()
Returns the type of the message.


getMessageId

public int getMessageId()
Returns the MQTT message ID.


setMessageId

public void setMessageId(int msgId)
Sets the MQTT message ID.


getKey

public String getKey()
Returns a key associated with the message. For most message types this will be unique. For connect, disconnect and ping only one message of this type is allowed so a fixed key will be returned

Returns:
key a key associated with the message

getHeader

public byte[] getHeader()
                 throws MqttException
Throws:
MqttException

getVariableHeader

protected abstract byte[] getVariableHeader()
                                     throws MqttException
Throws:
MqttException

isMessageIdRequired

public boolean isMessageIdRequired()
Returns whether or not this message needs to include a message ID.


createWireMessage

public static MqttWireMessage createWireMessage(MqttPersistable data)
                                         throws MqttException
Throws:
MqttException

createWireMessage

public static MqttWireMessage createWireMessage(byte[] bytes)
                                         throws MqttException
Throws:
MqttException

encodeMBI

protected static byte[] encodeMBI(long number)

readMBI

protected static MultiByteInteger readMBI(DataInputStream in)
                                   throws IOException
Decodes an MQTT Multi-Byte Integer from the given stream.

Throws:
IOException

encodeMessageId

protected byte[] encodeMessageId()
                          throws MqttException
Throws:
MqttException

isRetryable

public boolean isRetryable()

setDuplicate

public void setDuplicate(boolean duplicate)

encodeUTF8

protected void encodeUTF8(DataOutputStream dos,
                          String stringToEncode)
                   throws MqttException
Encodes a String given into UTF-8, before writing this to the DataOutputStream the length of the encoded string is encoded into two bytes and then written to the DataOutputStream. @link{DataOutputStream#writeUFT(String)} should be no longer used. @link{DataOutputStream#writeUFT(String)} does not correctly encode UTF-16 surrogate characters.

Parameters:
dos - The stream to write the encoded UTF-8 String to.
stringToEncode - The String to be encoded
Throws:
MqttException - Thrown when an error occurs with either the encoding or writing the data to the stream

decodeUTF8

protected String decodeUTF8(DataInputStream input)
                     throws MqttException
Decodes a UTF-8 string from the DataInputStream provided. @link(DataInoutStream#readUTF()) should be no longer used, because @link(DataInoutStream#readUTF()) does not decode UTF-16 surrogate characters correctly.

Parameters:
input - The input stream from which to read the encoded string
Returns:
a decoded String from the DataInputStream
Throws:
MqttException - thrown when an error occurs with either reading from the stream or decoding the encoded string.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013. All Rights Reserved.