class MqttRails::Packet::Unsubscribe
Constants
- ATTR_DEFAULTS
Default attribute values
Attributes
topics[RW]
One or more topic paths to unsubscribe from
Public Class Methods
new(args={})
click to toggle source
Create a new Unsubscribe
packet
Calls superclass method
MqttRails::Packet::Base::new
# File lib/mqtt_rails/packet/unsubscribe.rb, line 33 def initialize(args={}) super(ATTR_DEFAULTS.merge(args)) end
Public Instance Methods
encode_body()
click to toggle source
Get serialisation of packet's body
# File lib/mqtt_rails/packet/unsubscribe.rb, line 47 def encode_body if @topics.empty? raise MqttRails::PacketFormatException.new( "No topics given when serialising packet") end body = encode_short(@id) topics.each { |topic| body += encode_string(topic) } return body end
inspect()
click to toggle source
Returns a human readable string, summarising the properties of the packet
# File lib/mqtt_rails/packet/unsubscribe.rb, line 76 def inspect "\#<#{self.class}: 0x%2.2X, %s>" % [ id, topics.map { |t| "'#{t}'" }.join(', ') ] end
parse_body(buffer)
click to toggle source
Parse the body (variable header and payload) of a packet
Calls superclass method
MqttRails::Packet::Base#parse_body
# File lib/mqtt_rails/packet/unsubscribe.rb, line 58 def parse_body(buffer) super(buffer) @id = shift_short(buffer) while buffer.bytesize > 0 @topics << shift_string(buffer) end end
topics=(value)
click to toggle source
Set one or more topic paths to unsubscribe from
# File lib/mqtt_rails/packet/unsubscribe.rb, line 38 def topics=(value) if value.is_a?(Array) @topics = value else @topics = [value] end end
validate_flags()
click to toggle source
Check that fixed header flags are valid for this packet type @private
# File lib/mqtt_rails/packet/unsubscribe.rb, line 68 def validate_flags if @flags != [false, true, false, false] raise MqttRails::PacketFormatException.new( "Invalid flags in UNSUBSCRIBE packet header") end end