Class: Biryani::HPACK::DynamicTable

Inherits:
Object
  • Object
show all
Defined in:
lib/biryani/hpack/dynamic_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit) ⇒ DynamicTable

Returns a new instance of DynamicTable.

Parameters:



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

#limitObject (readonly)

Returns the value of attribute limit.



4
5
6
# File 'lib/biryani/hpack/dynamic_table.rb', line 4

def limit
  @limit
end

#sizeObject (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?

Parameters:

Returns:

  • (Array, nil)


46
47
48
# File 'lib/biryani/hpack/dynamic_table.rb', line 46

def [](index)
  @table[index]
end

#chomp!(new_limit) ⇒ Object

Parameters:



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_entriesInteger

Returns:



14
15
16
# File 'lib/biryani/hpack/dynamic_table.rb', line 14

def count_entries
  @table.length
end

#find_field(name, value) ⇒ Array, Integer

Parameters:

Returns:



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

Parameters:

Returns:



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

Parameters:



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

Parameters:



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