Method: AMQ::Protocol::Basic.decode_properties

Defined in:
lib/amq/protocol/client.rb

.decode_properties(data) ⇒ Object



1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
# File 'lib/amq/protocol/client.rb', line 1572

def self.decode_properties(data)
  offset, data_length, properties = 0, data.bytesize, {}

  compressed_index = data[offset, 2].unpack(PACK_UINT16)[0]
  offset += 2
  while data_length > offset
    DECODE_PROPERTIES_KEYS.each do |key|
      next unless compressed_index >= key
      compressed_index -= key
      name = DECODE_PROPERTIES[key] || raise(RuntimeError.new("No property found for index #{index.inspect}!"))
      case DECODE_PROPERTIES_TYPE[key]
      when :shortstr
        size = data[offset, 1].unpack(PACK_CHAR)[0]
        offset += 1
        result = data[offset, size]
      when :octet
        size = 1
        result = data[offset, size].unpack(PACK_CHAR).first
      when :timestamp
        size = 8
        result = Time.at(data[offset, size].unpack(PACK_UINT64_BE).last)
      when :table
        size = 4 + data[offset, 4].unpack(PACK_UINT32)[0]
        result = Table.decode(data[offset, size])
      end
      properties[name] = result
      offset += size
    end
  end

  properties
end