Class: PahoMqtt::Packet::Pubrel

Inherits:
PahoMqtt::Packet show all
Defined in:
lib/paho.mqtt/packet_manager.rb

Overview

Class representing an MQTT Publish Release packet

Constant Summary collapse

ATTR_DEFAULTS =

Default attribute values

{
  :flags => [false, true, false, false],
}

Instance Attribute Summary

Attributes inherited from PahoMqtt::Packet

#body_length, #flags, #id, #version

Instance Method Summary collapse

Methods inherited from PahoMqtt::Packet

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

Constructor Details

#initialize(args = {}) ⇒ Pubrel

Create a new Pubrel packet



692
693
694
# File 'lib/paho.mqtt/packet_manager.rb', line 692

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

Instance Method Details

#encode_bodyObject

Get serialisation of packet’s body



697
698
699
# File 'lib/paho.mqtt/packet_manager.rb', line 697

def encode_body
  encode_short(@id)
end

#inspectObject

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



719
720
721
# File 'lib/paho.mqtt/packet_manager.rb', line 719

def inspect
  "\#<#{self.class}: 0x%2.2X>" % id
end

#parse_body(buffer) ⇒ Object

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



702
703
704
705
706
707
708
# File 'lib/paho.mqtt/packet_manager.rb', line 702

def parse_body(buffer)
  super(buffer)
  @id = shift_short(buffer)
  unless buffer.empty?
    raise "Extra bytes at end of Publish Release packet"
  end
end

#validate_flagsObject

Check that fixed header flags are valid for this packet type



712
713
714
715
716
# File 'lib/paho.mqtt/packet_manager.rb', line 712

def validate_flags
  if @flags != [false, true, false, false]
    raise "Invalid flags in PUBREL packet header"
  end
end