Class: MQTT::SN::Packet::Connect
Constant Summary collapse
- DEFAULTS =
{ request_will: false, clean_session: true, keep_alive: 15 }.freeze
Constants inherited from Packet
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#keep_alive ⇒ Object
Returns the value of attribute keep_alive.
Attributes inherited from Packet
#body_length, #flags, #id, #version
Instance Method Summary collapse
-
#encode_body ⇒ Object
Get serialisation of packet's body.
- #parse_body(buffer) ⇒ Object
Methods inherited from Packet
create_from_header, #dup, #initialize, #inspect, #message_id, #message_id=, parse, parse_header, read, read_byte, #to_s, #type_id, #type_name, #update_attributes, #validate_flags
Constructor Details
This class inherits a constructor from MQTT::Packet
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
235 236 237 |
# File 'lib/mqtt/sn/packet.rb', line 235 def client_id @client_id end |
#keep_alive ⇒ Object
Returns the value of attribute keep_alive.
234 235 236 |
# File 'lib/mqtt/sn/packet.rb', line 234 def keep_alive @keep_alive end |
Instance Method Details
#encode_body ⇒ Object
Get serialisation of packet's body
244 245 246 247 248 249 250 |
# File 'lib/mqtt/sn/packet.rb', line 244 def encode_body if @client_id.nil? || @client_id.empty? || @client_id.length > 23 raise "Invalid client identifier when serialising packet" end [encode_flags, 0x01, keep_alive, client_id].pack("CCna*") end |
#parse_body(buffer) ⇒ Object
252 253 254 255 256 257 258 |
# File 'lib/mqtt/sn/packet.rb', line 252 def parse_body(buffer) flags, protocol_id, self.keep_alive, self.client_id = buffer.unpack("CCna*") raise ProtocolException, "Unsupported protocol ID number: #{protocol_id}" if protocol_id != 0x01 parse_flags(flags) end |