implement encode / decode of Huffman trees