Class: MqttRails::Packet::Pubrel
- Defined in:
- lib/mqtt_rails/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
-
#encode_body ⇒ Object
Get serialisation of packet’s body.
-
#initialize(args = {}) ⇒ Pubrel
constructor
Create a new Pubrel packet.
-
#inspect ⇒ Object
Returns a human readable string, summarising the properties of the packet.
-
#parse_body(buffer) ⇒ Object
Parse the body (variable header and payload) of a packet.
-
#validate_flags ⇒ Object
Check that fixed header flags are valid for this packet type.
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
29 30 31 |
# File 'lib/mqtt_rails/packet/pubrel.rb', line 29 def initialize(args={}) super(ATTR_DEFAULTS.merge(args)) end |
Instance Method Details
#encode_body ⇒ Object
Get serialisation of packet’s body
34 35 36 |
# File 'lib/mqtt_rails/packet/pubrel.rb', line 34 def encode_body encode_short(@id) end |
#inspect ⇒ Object
Returns a human readable string, summarising the properties of the packet
57 58 59 |
# File 'lib/mqtt_rails/packet/pubrel.rb', line 57 def inspect "\#<#{self.class}: 0x%2.2X>" % id end |
#parse_body(buffer) ⇒ Object
Parse the body (variable header and payload) of a packet
39 40 41 42 43 44 45 |
# File 'lib/mqtt_rails/packet/pubrel.rb', line 39 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_flags ⇒ Object
Check that fixed header flags are valid for this packet type
49 50 51 52 53 54 |
# File 'lib/mqtt_rails/packet/pubrel.rb', line 49 def validate_flags if @flags != [false, true, false, false] raise MqttRails::PacketFormatException.new( "Invalid flags in #{type_name} packet header") end end |