public void Decoding() { NetHuffman.Coder coder = new NetHuffman.Coder(HuffmanTableDefinition.Basic_abcd); byte[] decoded = new byte[] { 97, 98, 99, 100 }; byte[] buffer = coder.Decode(new byte[] { 27 }); Assert.AreEqual(decoded.Length, buffer.Length); for (int i = 0; i < buffer.Length; i++) { Assert.AreEqual(buffer[i], decoded[i]); } }
public void EncodingAndDecoding() { NetHuffman.Coder coder = new NetHuffman.Coder(HuffmanTableDefinition.Basic_abcd); byte[] buffer = System.Text.Encoding.UTF8.GetBytes("abcd"); byte[] decoded = coder.Decode(coder.Encode(buffer)); Assert.AreEqual(buffer.Length, decoded.Length); for (int i = 0; i < buffer.Length; i++) { Assert.AreEqual(buffer[i], decoded[i]); } }
static void Main(string[] args) { NetHuffman.Tree tree = new NetHuffman.Tree(); tree.BuildDictionary("this is just a test"); NetHuffman.Coder coder = new NetHuffman.Coder(tree); byte[] decoded = Encoding.UTF8.GetBytes("this is just a test"); Console.WriteLine(decoded.Length); byte[] encoded; uint size = coder.Encode(decoded, out encoded); Console.WriteLine(encoded.Length); coder.Decode(encoded, out decoded, size); Console.WriteLine(Encoding.UTF8.GetString(decoded)); }