lib/qubitro-mqtt/packet.rb in qubitro-mqtt-0.0.6 vs lib/qubitro-mqtt/packet.rb in qubitro-mqtt-0.0.7

- old
+ new

@@ -420,15 +420,15 @@ attr_accessor :will_retain # The payload of the Will message attr_accessor :will_payload - # The username for authenticating with the server - attr_accessor :username + # The deviceId for authenticating with the server + attr_accessor :deviceId - # The password for authenticating with the server - attr_accessor :password + # The deviceToken for authenticating with the server + attr_accessor :deviceToken # Default attribute values ATTR_DEFAULTS = { :client_id => nil, :clean_session => true, @@ -436,12 +436,12 @@ :will_topic => nil, :will_qos => 0, :ack_timeout => 15, :will_retain => false, :will_payload => '', - :username => nil, - :password => nil + :deviceId => nil, + :deviceToken => nil } # Create a new Client Connect packet def initialize(args = {}) super(ATTR_DEFAULTS.merge(args)) @@ -477,23 +477,23 @@ @connect_flags = 0 @connect_flags |= 0x02 if @clean_session @connect_flags |= 0x04 unless @will_topic.nil? @connect_flags |= ((@will_qos & 0x03) << 3) @connect_flags |= 0x20 if @will_retain - @connect_flags |= 0x40 unless @password.nil? - @connect_flags |= 0x80 unless @username.nil? + @connect_flags |= 0x40 unless @deviceToken.nil? + @connect_flags |= 0x80 unless @deviceId.nil? body += encode_bytes(@connect_flags) body += encode_short(@keep_alive) body += encode_string(@client_id) unless will_topic.nil? body += encode_string(@will_topic) # The MQTT v3.1 specification says that the payload is a UTF-8 string body += encode_string(@will_payload) end - body += encode_string(@username) unless @username.nil? - body += encode_string(@password) unless @password.nil? + body += encode_string(@deviceId) unless @deviceId.nil? + body += encode_string(@deviceToken) unless @deviceToken.nil? body end # Parse the body (variable header and payload) of a Connect packet def parse_body(buffer) @@ -519,24 +519,24 @@ @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) + @deviceId = shift_string(buffer) end if ((@connect_flags & 0x40) >> 6) == 0x01 && buffer.bytesize > 0 # rubocop: disable Style/GuardClause - @password = shift_string(buffer) + @deviceToken = shift_string(buffer) end end # Returns a human readable string, summarising the properties of the packet def inspect str = "\#<#{self.class}: " \ "keep_alive=#{keep_alive}" str += ', clean' if clean_session str += ", client_id='#{client_id}'" - str += ", username='#{username}'" unless username.nil? - str += ', password=...' unless password.nil? + str += ", deviceId='#{deviceId}'" unless deviceId.nil? + str += ', deviceToken=...' unless deviceToken.nil? str + '>' end # ---- Deprecated attributes and methods ---- # \ No newline at end of file