Class MqttCodec
MqttException.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe largest remaining length the protocol can express, 268435455. -
Method Summary
Modifier and TypeMethodDescriptionstatic MqttPacketdecode(int first, byte[] body) Decodes a packet from its first byte and its body.static byte[]encode(MqttPacket p) Encodes a packet to its wire form.static byte[]encodeRemainingLength(int value) Encodes a remaining length as the protocol's variable length integer.static intpacketLength(byte[] buf, int off, int len, int maxRemaining) Measures the first packet in a buffer.static MqttPacketread(InputStream in, int maxRemaining) Reads one packet from a stream, blocking until it is complete.static voidwrite(MqttPacket p, OutputStream out) Encodes a packet and writes it to a stream, without flushing it.
-
Field Details
-
MAX_REMAINING_LENGTH
public static final int MAX_REMAINING_LENGTHThe largest remaining length the protocol can express, 268435455.- See Also:
-
-
Method Details
-
encodeRemainingLength
public static byte[] encodeRemainingLength(int value) Encodes a remaining length as the protocol's variable length integer.
Parameters
value: 0 to 268435455
Returns
one to four bytes
-
encode
Encodes a packet to its wire form.
Parameters
p: the packet
Returns
the fixed header followed by the variable header and payload
Throws
MqttExceptionwhen the packet cannot be represented- Throws:
IOException
-
write
Encodes a packet and writes it to a stream, without flushing it.
Parameters
-
p: the packet -
out: the destination
- Throws:
IOException
-
-
packetLength
Measures the first packet in a buffer.
Parameters
-
buf: received bytes -
off: where the packet starts -
len: how many bytes are available fromoff -
maxRemaining: the largest remaining length to accept
Returns
the total size of the packet, fixed header included, or -1 when more bytes are needed
Throws
MqttExceptionwhen the length is malformed or above the limit- Throws:
IOException
-
-
read
Reads one packet from a stream, blocking until it is complete.
Parameters
-
in: the source -
maxRemaining: the largest remaining length to accept
Returns
the packet
Throws
EOFExceptionwhen the stream ends,MqttExceptionfor a malformed or oversized packet- Throws:
IOException
-
-
decode
Decodes a packet from its first byte and its body.
Parameters
-
first: the fixed header's first byte (type and flags) -
body: the bytes after the remaining length
Returns
the packet
- Throws:
IOException
-
-