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
- #find_field(name, value) ⇒ Array, Integer
- #find_name(name) ⇒ Array, Integer
-
#initialize(limit) ⇒ DynamicTable
constructor
A new instance of DynamicTable.
- #limit!(new_limit) ⇒ Object
- #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
51 52 53 54 55 56 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 51 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 |
#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
59 60 61 62 |
# File 'lib/biryani/hpack/dynamic_table.rb', line 59 def limit!(new_limit) chomp!(new_limit) @limit = new_limit 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 |