Class: MQTT::SN::Packet::Willtopic

Inherits:
Packet
  • Object
show all
Defined in:
lib/mqtt/sn/packet.rb

Constant Summary collapse

DEFAULTS =
{
  qos: 0,
  retain: false,
  topic_name: nil
}.freeze

Constants inherited from Packet

Packet::ATTR_DEFAULTS

Instance Attribute Summary collapse

Attributes inherited from Packet

#body_length, #flags, #id, #version

Instance Method Summary collapse

Methods inherited from Packet

create_from_header, #dup, #initialize, #inspect, #message_id, #message_id=, parse, parse_header, read, read_byte, #to_s, #type_id, #type_name, #update_attributes, #validate_flags

Constructor Details

This class inherits a constructor from MQTT::Packet

Instance Attribute Details

#topic_nameObject

Returns the value of attribute topic_name.



296
297
298
# File 'lib/mqtt/sn/packet.rb', line 296

def topic_name
  @topic_name
end

Instance Method Details

#encode_bodyObject



304
305
306
307
308
309
310
# File 'lib/mqtt/sn/packet.rb', line 304

def encode_body
  if topic_name.nil? || topic_name.empty?
    ""
  else
    [encode_flags, topic_name].pack("Ca*")
  end
end

#parse_body(buffer) ⇒ Object



312
313
314
315
316
317
318
319
320
# File 'lib/mqtt/sn/packet.rb', line 312

def parse_body(buffer)
  if buffer.length > 1
    flags, self.topic_name = buffer.unpack("Ca*")
  else
    flags, _ignore = buffer.unpack("C")
    self.topic_name = nil
  end
  parse_flags(flags)
end