class MQTT::MQTT::MQTT::Packet::Connack

Class representing an MQTT Connect Acknowledgment Packet

Constants

ATTR_DEFAULTS

Default attribute values

Attributes

return_code[RW]

The return code (defaults to 0 for connection accepted)

session_present[RW]

Session Present flag

Public Class Methods

new(args={}) click to toggle source

Create a new Client Connect packet

Calls superclass method
# File lib/mqttbridge/packet.rb, line 594
def initialize(args={})
  # We must set flags before other attributes
  @connack_flags = [false, false, false, false, false, false, false, false]
  super(ATTR_DEFAULTS.merge(args))
end

Public Instance Methods

encode_body() click to toggle source

Get serialisation of packet's body

# File lib/mqttbridge/packet.rb, line 635
def encode_body
  body = ''
  body += encode_bits(@connack_flags)
  body += encode_bytes(@return_code.to_i)
  return body
end
inspect() click to toggle source

Returns a human readable string, summarising the properties of the packet

# File lib/mqttbridge/packet.rb, line 657
def inspect
  "\#<#{self.class}: 0x%2.2X>" % return_code
end
parse_body(buffer) click to toggle source

Parse the body (variable header and payload) of a Connect Acknowledgment packet

Calls superclass method
# File lib/mqttbridge/packet.rb, line 643
def parse_body(buffer)
  super(buffer)
  @connack_flags = shift_bits(buffer)
  unless @connack_flags[1,7] == [false, false, false, false, false, false, false]
    raise ProtocolException.new("Invalid flags in Connack variable header")
  end
  @return_code = shift_byte(buffer)
  unless buffer.empty?
    raise ProtocolException.new("Extra bytes at end of Connect Acknowledgment packet")
  end
          pubACK(@return_code)
end
return_msg() click to toggle source

Get a string message corresponding to a return code

# File lib/mqttbridge/packet.rb, line 615
def return_msg
  case return_code
    when 0x00
      "Connection Accepted"
    when 0x01
      "Connection refused: unacceptable protocol version"
    when 0x02
      "Connection refused: client identifier rejected"
    when 0x03
      "Connection refused: server unavailable"
    when 0x04
      "Connection refused: bad user name or password"
    when 0x05
      "Connection refused: not authorised"
    else
      "Connection refused: error code #{return_code}"
  end
end
session_present=(arg) click to toggle source

Set the Session Present flag

# File lib/mqttbridge/packet.rb, line 606
def session_present=(arg)
  if arg.kind_of?(Integer)
    @connack_flags[0] = (arg == 0x1)
  else
    @connack_flags[0] = arg
  end
end