class MQTT::SN::Packet::Connect

Constants

DEFAULTS

Attributes

client_id[RW]
keep_alive[RW]

Public Instance Methods

encode_body() click to toggle source

Get serialisation of packet's body

# 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) click to toggle source
# 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