bool MQTTPublish::deserialize(uint8_t* buf){ uint8_t pos = 2; _type = *buf & 0xf0; if(_type != MQTT_TYPE_PUBLISH){ return false; } RemainingLength remLen; _flags = *buf & 0x0f; remLen.deserialize(buf + 1); _remainLength = remLen.decode(); buf += 1 + remLen.getSize(); _topic = string((char*)buf + 2, getUint16(buf)); buf += _topic.size() + 2; if(getQos()){ _messageId = getUint16(buf); buf += 2; pos += 2; } _len = _remainLength - _topic.size() - pos; _payload = mqcalloc(_len); memcpy(_payload, buf, _len); return true; }
bool MQTTSubAck::deserialize(uint8_t* buf){ RemainingLength remLen; remLen.encode(_remainLength); _type = *buf & 0xf0; if(_type != MQTT_TYPE_SUBACK){ return false; } _flags = *buf++ & 0x0f; remLen.deserialize(buf); _messageId = getUint16(buf + remLen.getSize()); _qos = *(buf + remLen.getSize() + 2); return true; }
bool MQTTMessage::deserialize(uint8_t* buf){ RemainingLength remLen; _type = *buf & 0xf0; _flags = *buf & 0x0f; remLen.deserialize(buf + 1); _remainLength = remLen.decode(); switch(_type){ case MQTT_TYPE_PINGRESP: return true; break; case MQTT_TYPE_UNSUBACK: case MQTT_TYPE_PUBACK: _messageId = getUint16(buf + 2); break; default: return false; } return true; }