Skip to content

Commit

Permalink
Fix decoding of fixed header
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoutp committed Jan 27, 2018
1 parent 8915d61 commit bd97172
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/mqtt_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ abstract class MqttMessage {
* - a payload (message specific)
*/
MqttMessage.decode(List<int> data, [bool debugMessage = false]) {
decodeFixedHeader(data);
num vhLen = decodeVariableHeader(data.sublist(2));
if (data.length > 2 + vhLen) {
decodePayload(data.sublist(2 + vhLen));
num fhLen = decodeFixedHeader(data);
num vhLen = decodeVariableHeader(data.sublist(fhLen));
if (data.length > fhLen + vhLen) {
decodePayload(data.sublist(fhLen + vhLen));
}

if (debugMessage) {
Expand Down Expand Up @@ -137,9 +137,11 @@ abstract class MqttMessage {
* bit 2 - 1 : Qos Level
* bit 0 : RETAIN
*
* Byte 2 : Remaining length
* Byte 2 : Remaining length
*
* Returns length of fixed header.
*/
decodeFixedHeader(data) {
num decodeFixedHeader(data) {
type = data[0] >> 4;
DUP = data[0] & 0x1000;
QoS = (data[0]>>1) & QOS_ALL;
Expand All @@ -158,6 +160,8 @@ abstract class MqttMessage {
} while ( (digit & 0x80) != 0);

len = remLength + 2;

return pos;
}

/**
Expand Down

0 comments on commit bd97172

Please sign in to comment.