Class: MQTT::SN::Packet::Connect

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

Constant Summary collapse

DEFAULTS =
{
  :request_will => false,
  :clean_session => true,
  :keep_alive => 15
}

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

#client_idObject

Returns the value of attribute client_id


242
243
244
# File 'lib/mqtt/sn/packet.rb', line 242

def client_id
  @client_id
end

#keep_aliveObject

Returns the value of attribute keep_alive


241
242
243
# File 'lib/mqtt/sn/packet.rb', line 241

def keep_alive
  @keep_alive
end

Instance Method Details

#encode_bodyObject

Get serialisation of packet's body


251
252
253
254
255
256
257
# File 'lib/mqtt/sn/packet.rb', line 251

def encode_body
  if @client_id.nil? or @client_id.length < 1 or @client_id.length > 23
    raise "Invalid client identifier when serialising packet"
  end

  [encode_flags, 0x01, keep_alive, client_id].pack('CCna*')
end

#parse_body(buffer) ⇒ Object


259
260
261
262
263
264
265
266
267
# File 'lib/mqtt/sn/packet.rb', line 259

def parse_body(buffer)
  flags, protocol_id, self.keep_alive, self.client_id = buffer.unpack('CCna*')

  if protocol_id != 0x01
    raise ProtocolException.new("Unsupported protocol ID number: #{protocol_id}")
  end

  parse_flags(flags)
end