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 }.freeze
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.
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 |