huffman-decode ( bytes -- string )


Vocabulary
http2.hpack.huffman

Inputs
bytesan object


Outputs
stringan object


Definition


:: huffman-decode ( bytes -- string )
BV{ } clone :> byte-vector 0 0 bytes bytes-to-bits [
[ 2 * ] 2dip 1 0 ? swap 1 [ + ] 2bi@ 2dup 2array
huffman-table index [
dup EOS = [
"End of Stream in huffman encoded string"
hpack-huffman-error
] when byte-vector push 2drop 0 0
] when*
] each 7 > [
"Padding is too long in huffman encoded string"
hpack-huffman-error
] when EOS huffman-table nth
first integer>bit-array swap integer>bit-array tail? [
"Padding is not the most significant bits of the End of Stream..."
hpack-huffman-error
] unless byte-vector utf8 decode ;