Class: PahoMqtt::Packet::Suback

Inherits:
Base
  • Object
show all
Defined in:
lib/paho_mqtt/packet/suback.rb

Constant Summary collapse

ATTR_DEFAULTS =

Default attribute values

{
  :return_codes => [],
}

Instance Attribute Summary collapse

Attributes inherited from Base

#body_length, #flags, #id, #version

Instance Method Summary collapse

Methods inherited from Base

create_from_header, parse, parse_header, read, #to_s, #type_id, #type_name, #update_attributes, #validate_flags

Constructor Details

#initialize(args = {}) ⇒ Suback

Create a new Subscribe Acknowledgment packet



32
33
34
# File 'lib/paho_mqtt/packet/suback.rb', line 32

def initialize(args={})
  super(ATTR_DEFAULTS.merge(args))
end

Instance Attribute Details

#return_codesObject

An array of return codes, ordered by the topics that were subscribed to



24
25
26
# File 'lib/paho_mqtt/packet/suback.rb', line 24

def return_codes
  @return_codes
end

Instance Method Details

#encode_bodyObject

Get serialisation of packet’s body



49
50
51
52
53
54
55
56
# File 'lib/paho_mqtt/packet/suback.rb', line 49

def encode_body
  if @return_codes.empty?
    raise "no granted QoS given when serialising packet"
  end
  body = encode_short(@id)
  return_codes.each { |qos| body += encode_bytes(qos) }
  return body
end

#inspectObject

Returns a human readable string, summarising the properties of the packet



68
69
70
# File 'lib/paho_mqtt/packet/suback.rb', line 68

def inspect
  "\#<#{self.class}: 0x%2.2X, rc=%s>" % [id, return_codes.map{|rc| "0x%2.2X" % rc}.join(',')]
end

#parse_body(buffer) ⇒ Object

Parse the body (variable header and payload) of a packet



59
60
61
62
63
64
65
# File 'lib/paho_mqtt/packet/suback.rb', line 59

def parse_body(buffer)
  super(buffer)
  @id = shift_short(buffer)
  while(buffer.bytesize>0)
    @return_codes << shift_byte(buffer)
  end
end