def _encode_data(self): buffer = bytearray() # variable header buffer.extend(MQTTUtils.encode_string(self.protocol_name)) buffer.append(MQTTUtils.encode_byte(self.protocol_version)) connect_flags = 0x00 connect_flags |= 0x80 if self.has_username else 0x00 connect_flags |= 0x40 if self.has_passwd else 0x00 connect_flags |= 0x20 if self.will_retain else 0x00 connect_flags |= ((self.will_qos or 0x00) << 3) & 0x18 connect_flags |= 0x04 if self.will_flag else 0x00 connect_flags |= 0x02 if self.clean_session else 0x00 buffer.append(connect_flags) buffer.extend(MQTTUtils.encode_value(self.keep_alive)) # payload buffer.extend(MQTTUtils.encode_string(self.client_uid)) if self.will_flag: buffer.extend(MQTTUtils.encode_string(self.will_topic)) buffer.extend(MQTTUtils.encode_string(self.will_message)) if self.has_username: buffer.extend(MQTTUtils.encode_string(self.username)) if self.has_passwd: buffer.extend(MQTTUtils.encode_string(self.passwd)) return bytes(buffer)
def _encode_data(self): buffer = bytearray() buffer.extend(MQTTUtils.encode_value(self.id)) for intent in self.subscription_intents: topic, qos = intent buffer.extend(MQTTUtils.encode_string(topic)) buffer.append(MQTTUtils.encode_byte(qos) & self.QOS_PART_MASK) return bytes(buffer)
def _encode_data(self): buffer = bytearray() sp = self.SESSION_PRESENT if self.session_present else 0x00 buffer.append(MQTTUtils.encode_byte(sp)) buffer.append(MQTTUtils.encode_byte(self.return_code)) return bytes(buffer)