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.



262
263
264
# File 'lib/mqtt/sn/packet.rb', line 262

def return_code
  @return_code
end

Instance Method Details

#encode_bodyObject



280
281
282
283
284
# File 'lib/mqtt/sn/packet.rb', line 280

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



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

def parse_body(buffer)
  self.return_code = buffer.unpack1("C")
end

#return_msgObject

Get a string message corresponding to a return code



265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/mqtt/sn/packet.rb', line 265

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