This is a very good example of Huffman encoding. Please forgive me if I don't fully understand the code but it seems that in your test code you are re-using the tree created during encoding to decode the packed data. In practical use when two applications are involved I believe you would need to transfer the tree used for encoding in the first application to the second application so that it could be used in decoding. I don't see that functionality (or how it is accomplished) in your code.
This is a very good example of Huffman encoding. Please forgive me if I don't fully understand the code but it seems that in your test code you are re-using the tree created during encoding to decode the packed data. In practical use when two applications are involved I believe you would need to transfer the tree used for encoding in the first application to the second application so that it could be used in decoding. I don't see that functionality (or how it is accomplished) in your code.