Class: EventMachine::MQTTSN::Packet::Connect

Inherits:
EventMachine::MQTTSN::Packet show all
Defined in:
lib/em/mqtt-sn/packet.rb

Constant Summary collapse

DEFAULTS =
{
  :request_will => false,
  :clean_session => true,
  :keep_alive => 15
}

Instance Attribute Summary collapse

Attributes inherited from EventMachine::MQTTSN::Packet

#clean_session, #duplicate, #qos, #request_will, #retain, #topic_id_type

Instance Method Summary collapse

Methods inherited from EventMachine::MQTTSN::Packet

#initialize, parse, #to_s, #type_id, #update_attributes

Constructor Details

This class inherits a constructor from EventMachine::MQTTSN::Packet

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



140
141
142
# File 'lib/em/mqtt-sn/packet.rb', line 140

def client_id
  @client_id
end

#keep_aliveObject

Returns the value of attribute keep_alive.



139
140
141
# File 'lib/em/mqtt-sn/packet.rb', line 139

def keep_alive
  @keep_alive
end

Instance Method Details

#encode_bodyObject

Get serialisation of packet’s body



149
150
151
152
153
154
155
# File 'lib/em/mqtt-sn/packet.rb', line 149

def encode_body
  if @client_id.nil? or @client_id.length < 1 or @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



157
158
159
160
161
162
163
164
165
# File 'lib/em/mqtt-sn/packet.rb', line 157

def parse_body(buffer)
  flags, protocol_id, self.keep_alive, self.client_id = buffer.unpack('CCna*')

  if protocol_id != 0x01
    raise ProtocolException.new("Unsupported protocol ID number: #{protocol_id}")
  end

  parse_flags(flags)
end