Class: MqttRails::Packet::Suback
- Defined in:
- lib/mqtt_rails/packet/suback.rb
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 Base
#body_length, #flags, #id, #version
Instance Method Summary collapse
-
#encode_body ⇒ Object
Get serialisation of packet’s body.
-
#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 Base
create_from_header, parse, parse_header, read, #to_s, #type_id, #type_name, #update_attributes, #validate_flags
Constructor Details
#initialize(args = {}) ⇒ Suback
Create a new Subscribe Acknowledgment packet
32 33 34 |
# File 'lib/mqtt_rails/packet/suback.rb', line 32 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
24 25 26 |
# File 'lib/mqtt_rails/packet/suback.rb', line 24 def return_codes @return_codes end |
Instance Method Details
#encode_body ⇒ Object
Get serialisation of packet’s body
50 51 52 53 54 55 56 57 58 |
# File 'lib/mqtt_rails/packet/suback.rb', line 50 def encode_body if @return_codes.empty? raise MqttRails::PacketFormatException.new( "No granted QoS given when serialising packet") end body = encode_short(@id) return_codes.each { |qos| body += encode_bytes(qos) } return body end |
#inspect ⇒ Object
Returns a human readable string, summarising the properties of the packet
70 71 72 |
# File 'lib/mqtt_rails/packet/suback.rb', line 70 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
61 62 63 64 65 66 67 |
# File 'lib/mqtt_rails/packet/suback.rb', line 61 def parse_body(buffer) super(buffer) @id = shift_short(buffer) while buffer.bytesize > 0 @return_codes << shift_byte(buffer) end end |