public abstract class MqttWireMessage extends Object
Modifier and Type | Field and Description |
---|---|
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 |
protected static String |
STRING_ENCODING |
Constructor and Description |
---|
MqttWireMessage(byte type) |
Modifier and Type | Method and Description |
---|---|
static MqttWireMessage |
createWireMessage(byte[] bytes) |
static MqttWireMessage |
createWireMessage(int first,
byte[] data) |
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()
Returns a string representation of the object.
|
protected boolean duplicate
public static final byte MESSAGE_TYPE_CONNACK
public static final byte MESSAGE_TYPE_CONNECT
public static final byte MESSAGE_TYPE_DISCONNECT
public static final byte MESSAGE_TYPE_PINGREQ
public static final byte MESSAGE_TYPE_PINGRESP
public static final byte MESSAGE_TYPE_PUBACK
public static final byte MESSAGE_TYPE_PUBCOMP
public static final byte MESSAGE_TYPE_PUBLISH
public static final byte MESSAGE_TYPE_PUBREC
public static final byte MESSAGE_TYPE_PUBREL
public static final byte MESSAGE_TYPE_SUBACK
public static final byte MESSAGE_TYPE_SUBSCRIBE
public static final byte MESSAGE_TYPE_UNSUBACK
public static final byte MESSAGE_TYPE_UNSUBSCRIBE
protected int msgId
protected static final String STRING_ENCODING
public static MqttWireMessage createWireMessage(byte[] bytes) throws MqttException
MqttException
public static MqttWireMessage createWireMessage(int first, byte[] data) throws MqttException
MqttException
public static MqttWireMessage createWireMessage(MqttPersistable data) throws MqttException
MqttException
protected String decodeUTF8(DataInputStream input) throws MqttException
input
- The input stream from which to read the encoded stringMqttException
- thrown when an error occurs with either reading from the stream or decoding the encoded string.protected static byte[] encodeMBI(long number)
protected byte[] encodeMessageId() throws MqttException
MqttException
protected void encodeUTF8(DataOutputStream dos, String stringToEncode) throws MqttException
dos
- The stream to write the encoded UTF-8 String to.stringToEncode
- The String to be encodedMqttException
- Thrown when an error occurs with either the encoding or writing the data to the streampublic byte[] getHeader() throws MqttException
MqttException
public String getKey()
public int getMessageId()
protected abstract byte getMessageInfo()
public byte[] getPayload() throws MqttException
MqttException
public byte getType()
protected abstract byte[] getVariableHeader() throws MqttException
MqttException
public boolean isMessageIdRequired()
public boolean isRetryable()
protected static MultiByteInteger readMBI(DataInputStream in) throws IOException
IOException
public void setDuplicate(boolean duplicate)
public void setMessageId(int msgId)
public String toString()
Object
toString
method returns a
string that "textually represents" this object. The result should be a concise but informative
representation that is easy for a person to read. It is recommended that all subclasses override
this method.
The toString
method for class Object
returns a string consisting of the name of
the class of which the object is an instance, the at-sign character `@
', and the unsigned
hexadecimal representation of the hash code of the object. In other words, this method returns a
string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())