Class: Biryani::HPACK::DynamicTable
- Inherits:
-
Object
- Object
- Biryani::HPACK::DynamicTable
- Defined in:
- lib/biryani/hpack/dynamic_table.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #[](index) ⇒ Array?
- #chomp!(new_limit) ⇒ Object
- #count_entries ⇒ Integer
-
#entry_at(index) ⇒ Array
[name, value].
- #find_field(name, value) ⇒ Array, Integer
- #find_name(name) ⇒ Array, Integer
-
#initialize(limit) ⇒ DynamicTable
constructor
A new instance of DynamicTable.
- #limit!(new_limit) ⇒ Object
- #name_at(index) ⇒ String
- #store(name, value) ⇒ Object
Constructor Details
#initialize(limit) ⇒ DynamicTable
Returns a new instance of DynamicTable.
7 8 9 10 11 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 7 def initialize(limit) @table = [] @size = 0 @limit = limit end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
4 5 6 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 4 def limit @limit end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 4 def size @size end |
Instance Method Details
#[](index) ⇒ Array?
46 47 48 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 46 def [](index) @table[index] end |
#chomp!(new_limit) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 71 def chomp!(new_limit) while @size > new_limit n, v = @table.pop @size -= n.bytesize + v.bytesize + 32 end end |
#count_entries ⇒ Integer
14 15 16 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 14 def count_entries @table.length end |
#entry_at(index) ⇒ Array
Returns [name, value].
53 54 55 56 57 58 59 60 61 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 53 def entry_at(index) raise Error::HPACKDecodeError if index.zero? || index > STATIC_TABLE_SIZE + count_entries if index <= STATIC_TABLE_SIZE STATIC_TABLE[index - 1] else self[index - 1 - STATIC_TABLE_SIZE] end end |
#find_field(name, value) ⇒ Array, Integer
31 32 33 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 31 def find_field(name, value) @table.each_with_index.find { |nv, _| nv[0] == name && nv[1] == value } end |
#find_name(name) ⇒ Array, Integer
39 40 41 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 39 def find_name(name) @table.each_with_index.find { |nv, _| nv[0] == name } end |
#limit!(new_limit) ⇒ Object
79 80 81 82 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 79 def limit!(new_limit) chomp!(new_limit) @limit = new_limit end |
#name_at(index) ⇒ String
66 67 68 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 66 def name_at(index) entry_at(index)[0] end |
#store(name, value) ⇒ Object
20 21 22 23 24 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 20 def store(name, value) @table.unshift([name, value]) @size += name.bytesize + value.bytesize + 32 chomp!(@limit) end |