class MQTT::Packet::Suback

Class representing an MQTT Subscribe Acknowledgment packet

Constants

ATTR_DEFAULTS

Default attribute values

Attributes

return_codes[RW]

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

Public Class Methods

new(args = {}) click to toggle source

Create a new Subscribe Acknowledgment packet

Calls superclass method MQTT::Packet::new
# File lib/qubitro-mqtt/packet.rb, line 841
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/qubitro-mqtt/packet.rb, line 858
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) }
  body
end
granted_qos() click to toggle source

@deprecated Please use {#return_codes} instead

# File lib/qubitro-mqtt/packet.rb, line 882
def granted_qos
  return_codes
end
granted_qos=(args) click to toggle source

@deprecated Please use {#return_codes=} instead

# File lib/qubitro-mqtt/packet.rb, line 887
def granted_qos=(args)
  self.return_codes = args
end
inspect() click to toggle source

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

# File lib/qubitro-mqtt/packet.rb, line 875
def inspect
  "\#<#{self.class}: 0x%2.2X, rc=%s>" % [id, return_codes.map { |rc| '0x%2.2X' % rc }.join(',')]
end
parse_body(buffer) click to toggle source

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

Calls superclass method MQTT::Packet#parse_body
# File lib/qubitro-mqtt/packet.rb, line 868
def parse_body(buffer)
  super(buffer)
  @id = shift_short(buffer)
  @return_codes << shift_byte(buffer) while buffer.bytesize > 0
end
return_codes=(value) click to toggle source

Set the granted QoS value for each of the topics that were subscribed to Can either be an integer or an array or integers.

# File lib/qubitro-mqtt/packet.rb, line 847
def return_codes=(value)
  if value.is_a?(Array)
    @return_codes = value
  elsif value.is_a?(Integer)
    @return_codes = [value]
  else
    raise 'return_codes should be an integer or an array of return codes'
  end
end