Class: Protocol::MQTT::Packet::Unsubscribe
- Inherits:
-
Protocol::MQTT::Packet
- Object
- Protocol::MQTT::Packet
- Protocol::MQTT::Packet::Unsubscribe
- Defined in:
- lib/protocol/mqtt/packet/unsubscribe.rb
Overview
UNSUBSCRIBE (ยง3.10). Fixed header flags nibble is 0b0010 (MQTT-3.10.1-1).
Variable header: packet_id (u16) + v5 property block. Payload: one or more topic filters (utf8), no options byte.
Constant Summary collapse
- TYPE_ID =
UNSUBSCRIBE
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
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#packet_id ⇒ Object
readonly
Returns the value of attribute packet_id.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #encode_body(version) ⇒ Object
- #flags_nibble(_version) ⇒ Object
- #hash ⇒ Object
-
#initialize(packet_id:, filters:, properties: {}) ⇒ Unsubscribe
constructor
A new instance of Unsubscribe.
Methods inherited from Protocol::MQTT::Packet
decode, decode_from_body, #encode, encode_packet, register
Constructor Details
#initialize(packet_id:, filters:, properties: {}) ⇒ Unsubscribe
Returns a new instance of Unsubscribe.
19 20 21 22 23 24 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 19 def initialize(packet_id:, filters:, properties: {}) raise ArgumentError, "UNSUBSCRIBE requires at least one filter" if filters.empty? @packet_id = packet_id @filters = filters @properties = properties end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
16 17 18 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 16 def filters @filters end |
#packet_id ⇒ Object (readonly)
Returns the value of attribute packet_id.
16 17 18 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 16 def packet_id @packet_id end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
16 17 18 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 16 def properties @properties end |
Class Method Details
.decode_body(reader, flags:, version:) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 41 def self.decode_body(reader, flags:, version:) raise MalformedPacket, "UNSUBSCRIBE reserved flags must be 0b0010" if flags != 0b0010 packet_id = reader.read_u16 properties = version == 5 ? Property.decode(reader) : {} filters = [] filters << reader.read_utf8 while !reader.eof? raise MalformedPacket, "UNSUBSCRIBE must carry at least one filter" if filters.empty? new(packet_id: packet_id, filters: filters, properties: properties) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
52 53 54 55 56 57 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 52 def ==(other) other.is_a?(Unsubscribe) && other.packet_id == @packet_id && other.filters == @filters && other.properties == @properties end |
#encode_body(version) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 32 def encode_body(version) w = Codec::Writer.new w.write_u16(@packet_id) w.write(Property.encode(@properties)) if version == 5 @filters.each { |f| w.write_utf8(f) } w.bytes end |
#flags_nibble(_version) ⇒ Object
27 28 29 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 27 def flags_nibble(_version) 0b0010 end |
#hash ⇒ Object
61 62 63 |
# File 'lib/protocol/mqtt/packet/unsubscribe.rb', line 61 def hash [self.class, @packet_id, @filters, @properties].hash end |