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.



268
269
270
# File 'lib/mqtt/sn/packet.rb', line 268

def return_code
  @return_code
end

Instance Method Details

#encode_bodyObject



286
287
288
289
290
# File 'lib/mqtt/sn/packet.rb', line 286

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

  [return_code].pack('C')
end

#parse_body(buffer) ⇒ Object



292
293
294
# File 'lib/mqtt/sn/packet.rb', line 292

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

#return_msgObject

Get a string message corresponding to a return code



271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/mqtt/sn/packet.rb', line 271

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