Class: MQTT::SN::Packet::Publish

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

Constant Summary collapse

DEFAULTS =
{
  id: 0x00,
  duplicate: false,
  qos: 0,
  retain: false,
  topic_id_type: :normal
}.freeze

Constants inherited from Packet

Packet::ATTR_DEFAULTS

Instance Attribute Summary collapse

Attributes inherited from Packet

#body_length, #flags, #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

#dataObject

Returns the value of attribute data.



389
390
391
# File 'lib/mqtt/sn/packet.rb', line 389

def data
  @data
end

#idObject

Returns the value of attribute id.



388
389
390
# File 'lib/mqtt/sn/packet.rb', line 388

def id
  @id
end

#topic_idObject

Returns the value of attribute topic_id.



387
388
389
# File 'lib/mqtt/sn/packet.rb', line 387

def topic_id
  @topic_id
end

Instance Method Details

#encode_bodyObject



399
400
401
402
403
# File 'lib/mqtt/sn/packet.rb', line 399

def encode_body
  raise "id must be an Integer" unless id.is_a?(Integer)

  [encode_flags, encode_topic_id, id, data].pack("Cnna*")
end

#parse_body(buffer) ⇒ Object



405
406
407
408
409
# File 'lib/mqtt/sn/packet.rb', line 405

def parse_body(buffer)
  flags, topic_id, self.id, self.data = buffer.unpack("Cnna*")
  parse_flags(flags)
  parse_topic_id(topic_id)
end