Class: MQTT::SN::Packet::Connack

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

Constant Summary

Constants inherited from MQTT::SN::Packet

DEFAULTS

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

#return_codeObject

Returns the value of attribute return_code


271
272
273
# File 'lib/mqtt/sn/packet.rb', line 271

def return_code
  @return_code
end

Instance Method Details

#encode_bodyObject


289
290
291
292
293
294
295
# File 'lib/mqtt/sn/packet.rb', line 289

def encode_body
  unless return_code.is_a?(Integer)
    raise "return_code must be an Integer"
  end

  [return_code].pack('C')
end

#parse_body(buffer) ⇒ Object


297
298
299
# File 'lib/mqtt/sn/packet.rb', line 297

def parse_body(buffer)
  self.return_code = buffer.unpack('C')[0]
end

#return_msgObject

Get a string message corresponding to a return code


274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/mqtt/sn/packet.rb', line 274

def return_msg
  case return_code
    when 0x00
      "Accepted"
    when 0x01
      "Rejected: congestion"
    when 0x02
      "Rejected: invalid topic ID"
    when 0x03
      "Rejected: not supported"
    else
      "Rejected: error code #{return_code}"
  end
end