Class: MQTT::Packet::Pubrel

Inherits:
MQTT::Packet show all
Defined in:
lib/mqtt/packet.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 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

Constructor Details

#initialize(args = {}) ⇒ Pubrel

Create a new Pubrel packet


711
712
713
# File 'lib/mqtt/packet.rb', line 711

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

Instance Method Details

#encode_bodyObject

Get serialisation of packet's body


716
717
718
# File 'lib/mqtt/packet.rb', line 716

def encode_body
  encode_short(@id)
end

#inspectObject

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


738
739
740
# File 'lib/mqtt/packet.rb', line 738

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

#parse_body(buffer) ⇒ Object

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


721
722
723
724
725
726
727
# File 'lib/mqtt/packet.rb', line 721

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

#validate_flagsObject

Check that fixed header flags are valid for this packet type


731
732
733
734
735
# File 'lib/mqtt/packet.rb', line 731

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