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]
}.freeze

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, #dup, #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



676
677
678
# File 'lib/mqtt/packet.rb', line 676

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

Instance Method Details

#encode_bodyObject

Get serialisation of packet’s body



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

def encode_body
  encode_short(@id)
end

#inspectObject

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



704
705
706
# File 'lib/mqtt/packet.rb', line 704

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

#parse_body(buffer) ⇒ Object

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

Raises:



686
687
688
689
690
691
692
693
# File 'lib/mqtt/packet.rb', line 686

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:



697
698
699
700
701
# File 'lib/mqtt/packet.rb', line 697

def validate_flags
  return if @flags == [false, true, false, false]

  raise ProtocolException, 'Invalid flags in PUBREL packet header'
end