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/mqttbridge/sn/packet.rb, line 250
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) click to toggle source
# File lib/mqttbridge/sn/packet.rb, line 258
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