Class: MQTT::Packet::Suback

Inherits:
MQTT::Packet show all
Defined in:
lib/mqtt/packet.rb

Overview

Class representing an MQTT Subscribe Acknowledgment packet

Constant Summary collapse

ATTR_DEFAULTS =

Default attribute values

{
  :return_codes => [],
}

Instance Attribute Summary collapse

Attributes inherited from MQTT::Packet

#body_length, #flags, #id, #version

Instance Method Summary collapse

Methods inherited from MQTT::Packet

create_from_header, #message_id, #message_id=, 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


876
877
878
# File 'lib/mqtt/packet.rb', line 876

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


868
869
870
# File 'lib/mqtt/packet.rb', line 868

def return_codes
  @return_codes
end

Instance Method Details

#encode_bodyObject

Get serialisation of packet's body


893
894
895
896
897
898
899
900
# File 'lib/mqtt/packet.rb', line 893

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

#granted_qosObject

Deprecated.

Please use #return_codes instead


920
921
922
# File 'lib/mqtt/packet.rb', line 920

def granted_qos
  return_codes
end

#granted_qos=(args) ⇒ Object

Deprecated.

Please use #return_codes= instead


925
926
927
# File 'lib/mqtt/packet.rb', line 925

def granted_qos=(args)
  self.return_codes = args
end

#inspectObject

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


912
913
914
# File 'lib/mqtt/packet.rb', line 912

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


903
904
905
906
907
908
909
# File 'lib/mqtt/packet.rb', line 903

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