Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor generate_huffman_table task #167

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AllCops:

Layout/IndentHeredoc:
Exclude:
- 'lib/tasks/generate_huffman_table.rb'
- 'tasks/generate_huffman_table.rb'
- 'example/*'

Metrics/LineLength:
Expand Down
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Style/Documentation:
- 'test/**/*'
- 'example/helper.rb'
- 'example/upgrade_server.rb'
- 'lib/tasks/generate_huffman_table.rb'
- 'tasks/generate_huffman_table.rb'

# Offense count: 3
# Cop supports --auto-correct.
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'yard'
require 'open3'
require_relative 'lib/tasks/generate_huffman_table'

require_relative 'tasks/generate_huffman_table'

RSpec::Core::RakeTask.new(:spec) do |t|
t.exclude_pattern = './spec/hpack_test_spec.rb'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require_relative '../lib/http/2/huffman'

# TODO: Currently, regenerating this table will produce something different from
# the table shipped with this gem. It is however stable.
desc 'Generate Huffman precompiled table in huffman_statemachine.rb'
task :generate_table do
task :generate_huffman_table do
HuffmanTable::Node.generate_state_table
end

require_relative '../http/2/huffman'

# @private
module HuffmanTable
BITS_AT_ONCE = HTTP2::Header::Huffman::BITS_AT_ONCE
EOS = 256
Expand Down Expand Up @@ -102,7 +103,7 @@ def self.generate_state_table
id += 1
end

File.open(File.expand_path('../http/2/huffman_statemachine.rb', File.dirname(__FILE__)), 'w') do |f|
File.open(File.expand_path('../lib/http/2/huffman_statemachine.rb', File.dirname(__FILE__)), 'w') do |f|
f.print <<HEADER
# Machine generated Huffman decoder state machine.
# DO NOT EDIT THIS FILE.
Expand Down