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, read_byte, #to_s, #type_id, #type_name, #update_attributes

Constructor Details

#initialize(args = {}) ⇒ Pubrel

Create a new Pubrel packet



681
682
683
# File 'lib/mqtt/packet.rb', line 681

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

Instance Method Details

#encode_bodyObject

Get serialisation of packet’s body



686
687
688
# File 'lib/mqtt/packet.rb', line 686

def encode_body
  encode_short(@id)
end

#inspectObject

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



707
708
709
# File 'lib/mqtt/packet.rb', line 707

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

#parse_body(buffer) ⇒ Object

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

Raises:



691
692
693
694
695
696
697
# File 'lib/mqtt/packet.rb', line 691

def parse_body(buffer)
  super(buffer)
  @id = shift_short(buffer)

  return if buffer.empty?
  raise ProtocolException, 'Extra bytes at end of Publish Release packet'
end

#validate_flagsObject

Check that fixed header flags are valid for this packet type

Raises:



701
702
703
704
# File 'lib/mqtt/packet.rb', line 701

def validate_flags
  return if @flags == [false, true, false, false]
  raise ProtocolException, 'Invalid flags in PUBREL packet header'
end