Class: MQTT::SN::Packet::Connect
- Inherits:
-
MQTT::SN::Packet
- Object
- MQTT::SN::Packet
- MQTT::SN::Packet::Connect
- Defined in:
- lib/mqtt/sn/packet.rb
Constant Summary collapse
- DEFAULTS =
{ :request_will => false, :clean_session => true, :keep_alive => 15 }
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 MQTT::SN::Packet
#clean_session, #duplicate, #qos, #request_will, #retain, #topic_id_type
Instance Method Summary collapse
-
#encode_body ⇒ Object
Get serialisation of packet’s body.
- #parse_body(buffer) ⇒ Object
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
#client_id ⇒ Object
Returns the value of attribute client_id.
239 240 241 |
# File 'lib/mqtt/sn/packet.rb', line 239 def client_id @client_id end |
#keep_alive ⇒ Object
Returns the value of attribute keep_alive.
238 239 240 |
# File 'lib/mqtt/sn/packet.rb', line 238 def keep_alive @keep_alive end |
Instance Method Details
#encode_body ⇒ Object
Get serialisation of packet’s body
248 249 250 251 252 253 254 |
# File 'lib/mqtt/sn/packet.rb', line 248 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
256 257 258 259 260 261 262 263 264 |
# File 'lib/mqtt/sn/packet.rb', line 256 def parse_body(buffer) flags, protocol_id, self.keep_alive, self.client_id = buffer.unpack('CCna*') if protocol_id != 0x01 raise ProtocolException, "Unsupported protocol ID number: #{protocol_id}" end parse_flags(flags) end |