Class: MQTT::Packet::Suback
- Inherits:
-
MQTT::Packet
- Object
- MQTT::Packet
- MQTT::Packet::Suback
- Defined in:
- lib/mqtt/packet.rb
Overview
Class representing an MQTT Subscribe Acknowledgment packet
Constant Summary collapse
- ATTR_DEFAULTS =
Default attribute values
{ :return_codes => [] }
Instance Attribute Summary collapse
-
#return_codes ⇒ Object
An array of return codes, ordered by the topics that were subscribed to.
Attributes inherited from MQTT::Packet
#body_length, #flags, #id, #version
Instance Method Summary collapse
-
#encode_body ⇒ Object
Get serialisation of packet’s body.
-
#granted_qos ⇒ Object
deprecated
Deprecated.
Please use #return_codes instead
-
#granted_qos=(args) ⇒ Object
deprecated
Deprecated.
Please use #return_codes= instead
-
#initialize(args = {}) ⇒ Suback
constructor
Create a new Subscribe Acknowledgment packet.
-
#inspect ⇒ Object
Returns a human readable string, summarising the properties of the packet.
-
#parse_body(buffer) ⇒ Object
Parse the body (variable header and payload) of a packet.
Methods inherited from MQTT::Packet
create_from_header, #message_id, #message_id=, parse, parse_header, read, read_byte, #to_s, #type_id, #type_name, #update_attributes, #validate_flags
Constructor Details
#initialize(args = {}) ⇒ Suback
Create a new Subscribe Acknowledgment packet
838 839 840 |
# File 'lib/mqtt/packet.rb', line 838 def initialize(args = {}) super(ATTR_DEFAULTS.merge(args)) end |
Instance Attribute Details
#return_codes ⇒ Object
An array of return codes, ordered by the topics that were subscribed to
830 831 832 |
# File 'lib/mqtt/packet.rb', line 830 def return_codes @return_codes end |
Instance Method Details
#encode_body ⇒ Object
Get serialisation of packet’s body
855 856 857 858 859 860 861 862 |
# File 'lib/mqtt/packet.rb', line 855 def encode_body if @return_codes.empty? raise 'no granted QoS given when serialising packet' end body = encode_short(@id) return_codes.each { |qos| body += encode_bytes(qos) } body end |
#granted_qos ⇒ Object
Please use #return_codes instead
879 880 881 |
# File 'lib/mqtt/packet.rb', line 879 def granted_qos return_codes end |
#granted_qos=(args) ⇒ Object
Please use #return_codes= instead
884 885 886 |
# File 'lib/mqtt/packet.rb', line 884 def granted_qos=(args) self.return_codes = args end |
#inspect ⇒ Object
Returns a human readable string, summarising the properties of the packet
872 873 874 |
# File 'lib/mqtt/packet.rb', line 872 def inspect "\#<#{self.class}: 0x%2.2X, rc=%s>" % [id, return_codes.map { |rc| '0x%2.2X' % rc }.join(',')] end |
#parse_body(buffer) ⇒ Object
Parse the body (variable header and payload) of a packet
865 866 867 868 869 |
# File 'lib/mqtt/packet.rb', line 865 def parse_body(buffer) super(buffer) @id = shift_short(buffer) @return_codes << shift_byte(buffer) while buffer.bytesize > 0 end |