Class: PahoMqtt::Packet::Unsubscribe
- Inherits:
-
PahoMqtt::Packet
- Object
- PahoMqtt::Packet
- PahoMqtt::Packet::Unsubscribe
- Defined in:
- lib/paho.mqtt/packet_manager.rb
Overview
Class representing an MQTT Client Unsubscribe packet
Constant Summary collapse
- ATTR_DEFAULTS =
Default attribute values
{ :topics => [], :flags => [false, true, false, false], }
Instance Attribute Summary collapse
-
#topics ⇒ Object
One or more topic paths to unsubscribe from.
Attributes inherited from PahoMqtt::Packet
#body_length, #flags, #id, #version
Instance Method Summary collapse
-
#encode_body ⇒ Object
Get serialisation of packet’s body.
-
#initialize(args = {}) ⇒ Unsubscribe
constructor
Create a new Unsubscribe 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.
-
#validate_flags ⇒ Object
Check that fixed header flags are valid for this packet type.
Methods inherited from PahoMqtt::Packet
create_from_header, parse, parse_header, read, #to_s, #type_id, #type_name, #update_attributes
Constructor Details
#initialize(args = {}) ⇒ Unsubscribe
Create a new Unsubscribe packet
910 911 912 |
# File 'lib/paho.mqtt/packet_manager.rb', line 910 def initialize(args={}) super(ATTR_DEFAULTS.merge(args)) end |
Instance Attribute Details
#topics ⇒ Object
One or more topic paths to unsubscribe from
901 902 903 |
# File 'lib/paho.mqtt/packet_manager.rb', line 901 def topics @topics end |
Instance Method Details
#encode_body ⇒ Object
Get serialisation of packet’s body
924 925 926 927 928 929 930 931 |
# File 'lib/paho.mqtt/packet_manager.rb', line 924 def encode_body if @topics.empty? raise "no topics given when serialising packet" end body = encode_short(@id) topics.each { |topic| body += encode_string(topic) } return body end |
#inspect ⇒ Object
Returns a human readable string, summarising the properties of the packet
951 952 953 954 955 956 |
# File 'lib/paho.mqtt/packet_manager.rb', line 951 def inspect "\#<#{self.class}: 0x%2.2X, %s>" % [ id, topics.map {|t| "'#{t}'"}.join(', ') ] end |
#parse_body(buffer) ⇒ Object
Parse the body (variable header and payload) of a packet
934 935 936 937 938 939 940 |
# File 'lib/paho.mqtt/packet_manager.rb', line 934 def parse_body(buffer) super(buffer) @id = shift_short(buffer) while(buffer.bytesize>0) @topics << shift_string(buffer) end end |
#validate_flags ⇒ Object
Check that fixed header flags are valid for this packet type
944 945 946 947 948 |
# File 'lib/paho.mqtt/packet_manager.rb', line 944 def validate_flags if @flags != [false, true, false, false] raise "Invalid flags in UNSUBSCRIBE packet header" end end |