class MQTT::Packet::Connect
def parse_body(buffer)
def parse_body(buffer) super(buffer) @protocol_name = shift_string(buffer) @protocol_level = shift_byte(buffer).to_i if @protocol_name == 'MQIsdp' && @protocol_level == 3 @version = '3.1.0' elsif @protocol_name == 'MQTT' && @protocol_level == 4 @version = '3.1.1' else raise ProtocolException, "Unsupported protocol: #{@protocol_name}/#{@protocol_level}" end @connect_flags = shift_byte(buffer) @clean_session = ((@connect_flags & 0x02) >> 1) == 0x01 @keep_alive = shift_short(buffer) @client_id = shift_string(buffer) if ((@connect_flags & 0x04) >> 2) == 0x01 # Last Will and Testament @will_qos = ((@connect_flags & 0x18) >> 3) @will_retain = ((@connect_flags & 0x20) >> 5) == 0x01 @will_topic = shift_string(buffer) # The MQTT v3.1 specification says that the payload is a UTF-8 string @will_payload = shift_string(buffer) end if ((@connect_flags & 0x80) >> 7) == 0x01 && buffer.bytesize > 0 @username = shift_string(buffer) end if ((@connect_flags & 0x40) >> 6) == 0x01 && buffer.bytesize > 0 # rubocop: disable Style/GuardClause @password = shift_string(buffer) end end