545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
|
# File 'lib/biryani/hpack/huffman.rb', line 545
def self.decode(io, cursor, length)
res = ''.b
bits = 0
bits_len = 0
bytes = io.get_string(cursor, length).bytes
(length * 8).times do |i|
bits_len += 1
bits += 1 if (bytes[i / 8] & (1 << 7 - (i % 8))).positive?
raise Error::HuffmanDecodeError if bits == EOS
if (chr = DECODE_TABLE[[bits, bits_len]])
res << chr
bits = 0
bits_len = 0
else
bits <<= 1
end
end
raise Error::HuffmanDecodeError if bits_len.positive? && bits != (2 << bits_len) - 2 || bits_len >= 8
res
end
|