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

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

Constant Summary collapse

DEFAULTS =
{
  :duration => nil
}

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.



594
595
596
# File 'lib/mqtt/sn/packet.rb', line 594

def duration
  @duration
end

Instance Method Details

#encode_bodyObject



600
601
602
603
604
605
606
# File 'lib/mqtt/sn/packet.rb', line 600

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

#parse_body(buffer) ⇒ Object



608
609
610
# File 'lib/mqtt/sn/packet.rb', line 608

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