byte[] decode(byte[] buf) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Node node = root;
        int current = 0;
        int nbits = 0;
        for (byte bb : buf) {
            int b = bb & 0xFF;
            current = (current << 8) | b;
            nbits += 8;
            while (nbits >= 8) {
                int c = (current >>> (nbits - 8)) & 0xFF;
                node = node.children[c];
                if (node.children == null) {
                    // terminal node
                    baos.write(node.symbol);
                    nbits -= node.terminalBits;
                    node = root;
                } else {
                    // non-terminal node
                    nbits -= 8;
                }
            }
        }

        while (nbits > 0) {
            int c = (current << (8 - nbits)) & 0xFF;
            node = node.children[c];
            if (node.children != null || node.terminalBits > nbits) {
                break;
            }
            baos.write(node.symbol);
            nbits -= node.terminalBits;
            node = root;
        }

        return baos.toByteArray();
    }
This class was originally composed from the following classes in <a
href="https://github.com/twitter/hpack">Twitter Hpack</a>.
<p>
<ul>
<li>{@code com.twitter.hpack.HuffmanEncoder}</li>
<li>{@code com.twitter.hpack.HuffmanDecoder}</li>
<li>{@code com.twitter.hpack.HpackUtil}</li>
</ul>
netbare-core/src/main/java/com/github/megatronking/netbare/http2/Huffman.java