lib/protocol/hpack/huffman.rb in protocol-hpack-1.5.0 vs lib/protocol/hpack/huffman.rb in protocol-hpack-1.5.1
- old
+ new
@@ -6,12 +6,12 @@
# Copyright, 2015, by Tamir Duberstein.
# Copyright, 2018-2024, by Samuel Williams.
# Copyright, 2022, by Daniel Morrison.
# Copyright, 2024, by Nathan Froyd.
-require_relative 'huffman/machine'
-require_relative 'error'
+require_relative "huffman/machine"
+require_relative "error"
module Protocol
module HPACK
# Implementation of huffman encoding for HPACK.
class Huffman
@@ -23,12 +23,12 @@
#
# @param str [String]
# @return [String] binary string
def self.encode(str)
bitstring = str.each_byte.map {|chr| ENCODE_TABLE[chr]}.join
- bitstring << '1' * ((8 - bitstring.size) % 8)
- [bitstring].pack('B*')
+ bitstring << "1" * ((8 - bitstring.size) % 8)
+ [bitstring].pack("B*")
end
# Decodes provided Huffman coded string.
#
# @param buf [Buffer]
@@ -49,19 +49,19 @@
# Each transition is [emit, next]
# [emit] character to be emitted on this transition, empty string, or EOS.
# [next] next state number.
value, state = MACHINE[state][branch]
- raise CompressionError, 'Huffman decode error (EOS found)' if value == EOS
+ raise CompressionError, "Huffman decode error (EOS found)" if value == EOS
emit << value.chr if value
shift -= BITS_AT_ONCE
end
end
# Check whether partial input is correctly filled
unless state <= MAX_FINAL_STATE
- raise CompressionError, 'Huffman decode error (EOS invalid)'
+ raise CompressionError, "Huffman decode error (EOS invalid)"
end
emit.force_encoding(Encoding::BINARY)
end
# Huffman table as specified in https://tools.ietf.org/html/rfc7541#appendix-B
@@ -323,9 +323,9 @@
[0x7fffff0, 27],
[0x3ffffee, 26],
[0x3fffffff, 30],
].each(&:freeze).freeze
- ENCODE_TABLE = CODES.map {|c, l| [c].pack('N').unpack1('B*')[-l..-1]}.each(&:freeze).freeze
+ ENCODE_TABLE = CODES.map {|c, l| [c].pack("N").unpack1("B*")[-l..-1]}.each(&:freeze).freeze
end
end
end