def decode(bytes)
cursor, headers, total, saw_header = Cursor.new(bytes), [], 0, false
until cursor.done?
first = cursor.peek
if (first & 128).positive?
pair = lookup(cursor.integer(7))
elsif (first & 224) == 32
raise CompressionError if saw_header
capacity = cursor.integer(5)
raise CompressionError if capacity > @maximum
@capacity = capacity
evict
next
else
indexed = (first & 64).positive?
index = cursor.integer(indexed ? 6 : 4)
name = index.zero? ? cursor.string(limit: @header_limit - total) : lookup(index).first
value = cursor.string(limit: @header_limit - total)
pair = [name.freeze, value.freeze].freeze
add(pair) if indexed
end
total += entry_size(pair)
raise CompressionError if total > @header_limit
headers << pair
saw_header = true
end
headers.freeze
end