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_UINT32_X2).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