KDE PIM / Developers / API Docs / libkmime

KMime::Decoder Class Reference

Stateful decoder class, modelled after Stateful CTE decoder class. More...

#include <kmime_codecs.h>

Inherited by KMime::Base64Decoder, KMime::IdentityEnDecoder, KMime::QuotedPrintableDecoder, and KMime::UUDecoder.

List of all members.

Public Member Functions

Protected Member Functions

Protected Attributes

Friends


Detailed Description

Stateful decoder class, modelled after Stateful CTE decoder class.

See also:
QTextDecoder.

Overview

KMime decoders are designed to be able to process encoded data in chunks of arbitrary size and to work with output buffers of also arbitrary size. They maintain any state necessary to go on where the previous call left off.

The class consists of only two methods of interest:

See also:
decode, which decodes an input block and

finalize, which flushes any remaining data to the output stream.

Typically, you will create a decoder instance, call
See also:
decode as often as necessary, then call

finalize (most often a single call suffices, but it might be that during that call the output buffer is filled, so you should be prepared to call

finalize as often as necessary, ie. until it returns true).

Values

Both methods return true to indicate that they've finished their job. For
See also:
decode, a return value of true means that the current input block has been finished (false most often means that the output buffer is full, but that isn't required behavior. The

decode call is free to return at arbitrary times during processing).

For
See also:
finalize, a return value of true means that all data implicitly or explicitly stored in the decoder instance has been flushed to the output buffer. A false return value should be interpreted as "check if the output buffer is full and call me again", just as with

decode.

Pattern

Since the decoder maintains state, you can only use it once. After a sequence of input blocks has been processed, you
See also:
finalize the output and then delete the decoder instance. If you want to process another input block sequence, you create a new instance.
Typical usage (in contains the (base64-encoded) input data), taking into account all the conventions detailed above:

 KMime::Codec * codec = KMime::Codec::codecForName( "base64" );
 kdFatal( !codec ) << "No codec found for base64!" << endl;
 KMime::Decoder * dec = codec->makeDecoder();
 assert( dec ); // should not happen
 QByteArray out( 256 ); // small buffer is enough ;-)
 QByteArray::Iterator iit = in.begin();
 QByteArray::Iterator oit = out.begin();
 // decode the chunk
 while ( !dec->decode( iit, in.end(), oit, out.end() ) )
   if ( oit == out.end() ) { // output buffer full, process contents
     do_something_with( out );
     oit = out.begin();
   }
 // repeat while loop for each input block
 // ...
 // finish (flush remaining data from decoder):
 while ( !dec->finish( oit, out.end() ) )
   if ( oit == out.end() ) { // output buffer full, process contents
     do_something_with( out );
     oit = out.begin();
   }
 // now process last chunk:
 out.resize( oit - out.begin() );
 do_something_with( out );
 // _delete_ the decoder, but not the codec:
 delete dec;
 

Author:
Marc Mutz <mutz@kde.org>


Constructor & Destructor Documentation

KMime::Decoder::Decoder bool  withCRLF = false  )  [inline, protected]
 

Protected constructor.

Use

See also:
KMime::Codec::makeDecoder to create an instance. The bool parameter determines whether lines end with CRLF (true) or LF (false, default).

Member Function Documentation

virtual bool KMime::Decoder::decode const char *&  scursor,
const char *const   send,
char *&  dcursor,
const char *const   dend
[pure virtual]
 

Decode a chunk of data, maintaining state information between calls.

See class decumentation for calling conventions.

virtual bool KMime::Decoder::finish char *&  dcursor,
const char *const   dend
[pure virtual]
 

Call this method to finalize the output stream.

Writes all remaining data and resets the decoder. See

See also:
KMime::Codec for calling conventions.

The documentation for this class was generated from the following file: