Bugfix in variable int encoding for MQTT
This commit is contained in:
parent
dd6ef1b3b7
commit
bb3f92fe72
4 changed files with 140 additions and 5 deletions
|
|
@ -89,15 +89,14 @@ public class MqttPacketPublish extends MqttPacketHeader {
|
|||
// ------------------------------------------
|
||||
// - Application data
|
||||
|
||||
@CustomBinaryField(index = 3000, serializer = MqttPacketPublishPayloadSerializer.class)
|
||||
public byte[] payload;
|
||||
|
||||
|
||||
@Override
|
||||
public int calculatePayloadLength() {
|
||||
return payload == null ? 0 : payload.length;
|
||||
}
|
||||
|
||||
@CustomBinaryField(index = 3000, serializer = MqttPacketPublishPayloadSerializer.class)
|
||||
public byte[] payload;
|
||||
|
||||
// ------------------------------------------
|
||||
// Util methods
|
||||
// ------------------------------------------
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.io.OutputStream;
|
|||
|
||||
/**
|
||||
* Code from MQTT specification
|
||||
* @see <a href="http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180836">2.2.3 Remaining Length (variable length encoding scheme)</a>
|
||||
*/
|
||||
public class MqttVariableIntSerializer implements BinaryFieldSerializer<Integer> {
|
||||
|
||||
|
|
@ -60,7 +61,7 @@ public class MqttVariableIntSerializer implements BinaryFieldSerializer<Integer>
|
|||
x = x / 128;
|
||||
// if there are more data to encode, set the top bit of this byte
|
||||
if (x > 0)
|
||||
encodedByte = encodedByte & 128;
|
||||
encodedByte = encodedByte | 128;
|
||||
out.write(encodedByte);
|
||||
} while (x > 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue