lib/protocol/hpack/compressor.rb in protocol-hpack-1.5.0 vs lib/protocol/hpack/compressor.rb in protocol-hpack-1.5.1

- old
+ new

@@ -11,12 +11,12 @@ # Copyright, 2018, by Kenichi Nakamura. # Copyright, 2019, by Jingyi Chen. # Copyright, 2020, by Justin Mazzocchi. # Copyright, 2024, by Nathan Froyd. -require_relative 'context' -require_relative 'huffman' +require_relative "context" +require_relative "huffman" module Protocol module HPACK # Predefined options set for Compressor # http://mew.org/~kazu/material/2014-hpack.pdf @@ -73,25 +73,22 @@ # # @param value [Integer] value to encode # @param bits [Integer] number of available bits # @return [String] binary string def write_integer(value, bits) - limit = 2**bits - 1 + limit = (1 << bits) - 1 - return write_bytes([value].pack('C')) if value < limit + return @buffer << value if value < limit - bytes = [] - bytes.push(limit) unless bits.zero? + @buffer << limit unless bits.zero? value -= limit while value >= 128 - bytes.push((value % 128) + 128) + @buffer << ((value & 0x7f) + 128) value /= 128 end - bytes.push(value) - - write_bytes(bytes.pack('C*')) + @buffer << value end def huffman @context.huffman end