Class: Protocol::MQTT::Packet::Unsuback
- Inherits:
-
Protocol::MQTT::Packet
- Object
- Protocol::MQTT::Packet
- Protocol::MQTT::Packet::Unsuback
- Defined in:
- lib/protocol/mqtt/packet/unsuback.rb
Overview
UNSUBACK (§3.11).
v3.1.1: body is just the packet id — no per-filter results. v5: packet_id + property block + one reason code per filter.
Constant Summary collapse
- TYPE_ID =
UNSUBACK
Constants inherited from Protocol::MQTT::Packet
AUTH, CONNACK, CONNECT, DISCONNECT, PINGREQ, PINGRESP, PUBACK, PUBCOMP, PUBLISH, PUBREC, PUBREL, SUBACK, SUBSCRIBE, UNSUBACK, UNSUBSCRIBE
Instance Attribute Summary collapse
-
#packet_id ⇒ Object
readonly
Returns the value of attribute packet_id.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#reason_codes ⇒ Object
readonly
Returns the value of attribute reason_codes.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #encode_body(version) ⇒ Object
- #hash ⇒ Object
-
#initialize(packet_id:, reason_codes: [], properties: {}) ⇒ Unsuback
constructor
A new instance of Unsuback.
Methods inherited from Protocol::MQTT::Packet
decode, decode_from_body, #encode, encode_packet, #flags_nibble, register
Constructor Details
#initialize(packet_id:, reason_codes: [], properties: {}) ⇒ Unsuback
Returns a new instance of Unsuback.
20 21 22 23 24 |
# File 'lib/protocol/mqtt/packet/unsuback.rb', line 20 def initialize(packet_id:, reason_codes: [], properties: {}) @packet_id = packet_id @reason_codes = reason_codes @properties = properties end |
Instance Attribute Details
#packet_id ⇒ Object (readonly)
Returns the value of attribute packet_id.
17 18 19 |
# File 'lib/protocol/mqtt/packet/unsuback.rb', line 17 def packet_id @packet_id end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
17 18 19 |
# File 'lib/protocol/mqtt/packet/unsuback.rb', line 17 def properties @properties end |
#reason_codes ⇒ Object (readonly)
Returns the value of attribute reason_codes.
17 18 19 |
# File 'lib/protocol/mqtt/packet/unsuback.rb', line 17 def reason_codes @reason_codes end |
Class Method Details
.decode_body(reader, flags:, version:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/protocol/mqtt/packet/unsuback.rb', line 38 def self.decode_body(reader, flags:, version:) packet_id = reader.read_u16 if version == 5 properties = Property.decode(reader) reason_codes = [] reason_codes << reader.read_u8 while !reader.eof? raise MalformedPacket, "v5 UNSUBACK must carry at least one reason code" if reason_codes.empty? new(packet_id: packet_id, reason_codes: reason_codes, properties: properties) else new(packet_id: packet_id) end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
52 53 54 55 56 57 |
# File 'lib/protocol/mqtt/packet/unsuback.rb', line 52 def ==(other) other.is_a?(Unsuback) && other.packet_id == @packet_id && other.reason_codes == @reason_codes && other.properties == @properties end |
#encode_body(version) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/protocol/mqtt/packet/unsuback.rb', line 27 def encode_body(version) w = Codec::Writer.new w.write_u16(@packet_id) if version == 5 w.write(Property.encode(@properties)) @reason_codes.each { |rc| w.write_u8(rc) } end w.bytes end |
#hash ⇒ Object
61 62 63 |
# File 'lib/protocol/mqtt/packet/unsuback.rb', line 61 def hash [self.class, @packet_id, @reason_codes, @properties].hash end |