Class: Protocol::MQTT::Packet::Pubrel
- Inherits:
-
Protocol::MQTT::Packet
- Object
- Protocol::MQTT::Packet
- Protocol::MQTT::Packet::Pubrel
- Defined in:
- lib/protocol/mqtt/packet/pubrel.rb
Overview
PUBREL (§3.6) — QoS 2 release. Same body shape as PUBACK. Fixed header flags nibble is 0b0010 (MQTT-3.6.1-1).
Constant Summary collapse
- TYPE_ID =
PUBREL
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_code ⇒ Object
readonly
Returns the value of attribute reason_code.
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:, reason_code: ReasonCodes::SUCCESS, properties: {}) ⇒ Pubrel
constructor
A new instance of Pubrel.
Methods inherited from Protocol::MQTT::Packet
decode, decode_from_body, #encode, encode_packet, register
Constructor Details
#initialize(packet_id:, reason_code: ReasonCodes::SUCCESS, properties: {}) ⇒ Pubrel
Returns a new instance of Pubrel.
18 19 20 21 22 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 18 def initialize(packet_id:, reason_code: ReasonCodes::SUCCESS, properties: {}) @packet_id = packet_id @reason_code = reason_code @properties = properties end |
Instance Attribute Details
#packet_id ⇒ Object (readonly)
Returns the value of attribute packet_id.
15 16 17 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 15 def packet_id @packet_id end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
15 16 17 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 15 def properties @properties end |
#reason_code ⇒ Object (readonly)
Returns the value of attribute reason_code.
15 16 17 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 15 def reason_code @reason_code end |
Class Method Details
.decode_body(reader, flags:, version:) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 41 def self.decode_body(reader, flags:, version:) packet_id = reader.read_u16 if version == 5 && !reader.eof? reason_code = reader.read_u8 properties = reader.eof? ? {} : Property.decode(reader) new(packet_id: packet_id, reason_code: reason_code, properties: properties) else new(packet_id: packet_id) end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
53 54 55 56 57 58 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 53 def ==(other) other.is_a?(Pubrel) && other.packet_id == @packet_id && other.reason_code == @reason_code && other.properties == @properties end |
#encode_body(version) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 30 def encode_body(version) w = Codec::Writer.new w.write_u16(@packet_id) if version == 5 && !(@properties.empty? && @reason_code == ReasonCodes::SUCCESS) w.write_u8(@reason_code) w.write(Property.encode(@properties)) unless @properties.empty? end w.bytes end |
#flags_nibble(_version) ⇒ Object
25 26 27 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 25 def flags_nibble(_version) 0b0010 end |
#hash ⇒ Object
62 63 64 |
# File 'lib/protocol/mqtt/packet/pubrel.rb', line 62 def hash [self.class, @packet_id, @reason_code, @properties].hash end |