Example 2:
Adding a checksum.
All you have to do is to replace the
typedef-statement
typedef HuffmanCoder Coder;
in Example 1 by
typedef CoderPipe2<MD5SumCoder, HuffmanCoder> Coder;
The class CoderPipe2 combines the two L
E D A coders MD5SumCoder (the checksummer)
and HuffmanCoder into a single coder. If the pipe
is used for encoding, then the MD5SumCoder is used
first and the HuffmanCoder is applied
to its output. In decoding mode the situation is reversed.
The standard behaviour of a checksummer
like MD5SumCoder is as follows:
In encoding mode it reads the input stream
and computes a checksum;
the output data basically consists of the input data with the checksum
appended.
In decoding mode, the checksum is stripped from the input data and verified.
If the input is corrupted, the failure flag of the coder is set to indicate
this.
|