Class: PahoMqtt::Packet::Pubrel

Inherits:
Base
  • Object
show all
Defined in:
lib/paho_mqtt/packet/pubrel.rb

Constant Summary collapse

ATTR_DEFAULTS =

Default attribute values

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

Instance Attribute Summary

Attributes inherited from Base

#body_length, #flags, #id, #version

Instance Method Summary collapse

Methods inherited from Base

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



12
13
14
# File 'lib/paho_mqtt/packet/pubrel.rb', line 12

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

Instance Method Details

#encode_bodyObject

Get serialisation of packet’s body



17
18
19
# File 'lib/paho_mqtt/packet/pubrel.rb', line 17

def encode_body
  encode_short(@id)
end

#inspectObject

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



39
40
41
# File 'lib/paho_mqtt/packet/pubrel.rb', line 39

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

#parse_body(buffer) ⇒ Object

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



22
23
24
25
26
27
28
# File 'lib/paho_mqtt/packet/pubrel.rb', line 22

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



32
33
34
35
36
# File 'lib/paho_mqtt/packet/pubrel.rb', line 32

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