Default attribute values
The return code (defaults to 0 for connection accepted)
Session Present flag
Get serialisation of packet's body
# File lib/mqtt/packet.rb, line 631 def encode_body body = '' body += encode_bits(@connack_flags) body += encode_bytes(@return_code.to_i) return body end
Returns a human readable string, summarising the properties of the packet
# File lib/mqtt/packet.rb, line 652 def inspect "\#<#{self.class}: 0x%2.2X>" % return_code end
Parse the body (variable header and payload) of a Connect Acknowledgment packet
# File lib/mqtt/packet.rb, line 639 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 end
Get a string message corresponding to a return code
# File lib/mqtt/packet.rb, line 611 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
Set the Session Present flag
# File lib/mqtt/packet.rb, line 602 def session_present=(arg) if arg.kind_of?(Integer) @connack_flags[0] = (arg == 0x1) else @connack_flags[0] = arg end end