Base64Codec Class Reference

#include <Pt/Base64Codec.h>

A codec for base-64 encoding. More...

Inherits TextCodec< char, char >.

Public Types

typedef char intern_type
 Internal character type.
typedef char extern_type
 External character type.
typedef MBState state_type
 Conversion state type.

Public Member Functions

 Base64Codec (std::size_t ref=0)
 Default constructor.
virtual ~Base64Codec ()
 Destructor.
result in (MBState &s, const char *fbeg, const char *fend, const char *&fnext, char *tbeg, char *tend, char *&tnext) const
 Decodes a character sequence.
result out (MBState &state, const char *fbeg, const char *fend, const char *&fnext, char *tbeg, char *tend, char *&tnext) const
 Encodes a character sequence.
result unshift (MBState &state, char *to, char *to_end, char *&to_next) const
 Unshifts a character sequence.
int encoding () const
 Returns the encoding rate.
bool always_noconv () const
 Returns true if no conversion is required.
int length (MBState &state, const char *from, const char *end, std::size_t max) const
 Returns the number of the decoded characters.
int max_length () const
 Maximum length of an external sequence if one character is encoded.

Detailed Description

The base-64 encoding scheme is not a character encoding in the classical sense, but works very similar to other types of encodings. Base64Codec can be used with the basic text stream templates, where the internal and external character types are both char. The following example shows how text is converted to base-64:

std::ostringstream oss;
b64 << "Hello World!";
b64.flush();
Base64Codec(std::size_t ref=0)
Default constructor.
Definition Base64Codec.h:66
Converts character sequences using a codec.
Definition TextStream.h:236

The string stream serves as the output for the base-64 encoded text. It is important to terminate the output sequence by calling flush(), because the base-64 format requires padding at the end. Inserting std::endl also terminates the base-64 sequence.