Class: MQTT::SN::Packet::Disconnect

Inherits:
MQTT::SN::Packet show all
Defined in:
lib/mqtt/sn/packet.rb

Constant Summary collapse

DEFAULTS =
{
  duration: nil
}.freeze

Instance Attribute Summary collapse

Attributes inherited from MQTT::SN::Packet

#clean_session, #duplicate, #qos, #request_will, #retain, #topic_id_type

Instance Method Summary collapse

Methods inherited from MQTT::SN::Packet

#initialize, parse, #to_s, #type_id, #update_attributes

Constructor Details

This class inherits a constructor from MQTT::SN::Packet

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



588
589
590
# File 'lib/mqtt/sn/packet.rb', line 588

def duration
  @duration
end

Instance Method Details

#encode_bodyObject



594
595
596
597
598
599
600
# File 'lib/mqtt/sn/packet.rb', line 594

def encode_body
  if duration.nil? || duration.zero?
    ''
  else
    [duration].pack('n')
  end
end

#parse_body(buffer) ⇒ Object



602
603
604
# File 'lib/mqtt/sn/packet.rb', line 602

def parse_body(buffer)
  self.duration = buffer.length == 2 ? buffer.unpack1('n') : nil
end