Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Base64Encoder Class Reference

Base-64 encoding class. More...

#include <base64.h>

Collaboration diagram for Base64Encoder:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Base64Encoder (int _lwidth=0)
 Base64Encoder (const Base64Encoder &b)
 Copy-constructor as usual.

 ~Base64Encoder ()
 Destructor; a no-op...

Base64Encoderoperator= (const Base64Encoder &b)
 Standard assignment operator:.

void SetLWidth (int _lwidth)
 Set the line width for output formatting.

void reset ()
 Reset the encoder.

size_t EncodedSize (size_t inlen)
 Compute the required output buffer length.

ssize_t encode (const char *in, size_t inlen, char *out, size_t outlen)
 Encode binary data as base-64 ASCII.


Static Public Member Functions

ssize_t EncodeBuf (const char *in, size_t inlen, char *out, size_t outlen, int lwidth)
 Static version of encoding function.


Private Attributes

uint32 state
 Current encode state (carry).

int lwidth
 Line width to use in 4-tuples; 0 for unlimited.


Detailed Description

Base-64 encoding class.

Author:
Wolfgang Wieser ] wwieser (a) gmx <*> de [
This class only stores the internal carry of the base-64 encoding and is "C++-safe".

Definition at line 35 of file base64.h.


Constructor & Destructor Documentation

Base64Encoder::Base64Encoder int  _lwidth = 0  )  [inline]
 

Construct a base-64 encoder; lwidth is the line width; see SetLWidth()

Definition at line 44 of file base64.h.

References lwidth, and state.

Base64Encoder::Base64Encoder const Base64Encoder b  )  [inline]
 

Copy-constructor as usual.

Definition at line 46 of file base64.h.

References lwidth, and state.

Base64Encoder::~Base64Encoder  )  [inline]
 

Destructor; a no-op...

Definition at line 49 of file base64.h.


Member Function Documentation

ssize_t Base64Encoder::encode const char *  in,
size_t  inlen,
char *  out,
size_t  outlen
 

Encode binary data as base-64 ASCII.

You can encode very large data by calling this function repeatedly since this class has an internal state which saves the carry bytes from previous calls.

In order to have the carry flushed and the end-of-data indicator ('=') appended to the output, use inlen=0.

You can use the static variant EncodeBuf if you can encode all data in a single call.

Parameters:
in: input data to be encoded
inlen: length of input data in bytes
out: buffer to store output data
outlen: length of output buffer
Returns:
>=0 -> number of bytes in output;
-4 -> output buffer too small.
Note:
You can estimate the required output buffer size by calling the EncodedSize() function.

Definition at line 247 of file base64.cc.

References lwidth, ssize_t, and state.

Referenced by base64_ctest().

ssize_t Base64Encoder::EncodeBuf const char *  in,
size_t  inlen,
char *  out,
size_t  outlen,
int  lwidth
[static]
 

Static version of encoding function.

See the member function encode() for details.

Definition at line 253 of file base64.cc.

References ssize_t.

Referenced by do_test_base64().

size_t Base64Encoder::EncodedSize size_t  inlen  )  [inline]
 

Compute the required output buffer length.

Computes the length of the output buffer when encoding input of size inlen.

The returned value may be slightly too large but never too small.

Definition at line 86 of file base64.h.

References lwidth.

Base64Encoder& Base64Encoder::operator= const Base64Encoder b  )  [inline]
 

Standard assignment operator:.

Definition at line 52 of file base64.h.

References lwidth, and state.

void Base64Encoder::reset  )  [inline]
 

Reset the encoder.

This will clear the internal state (carry) so that new independent data can be encoded.

Note:
the current byte quartett count is also stored in state as 14 bit value so that the base64 text stays formatted even if you have to call encode() repeatedly. So, you don't try to set lwidth to values >2^14 (that is 2^14*4=65536 chars per line).

Definition at line 75 of file base64.h.

References state.

void Base64Encoder::SetLWidth int  _lwidth  )  [inline]
 

Set the line width for output formatting.

If set to 0, the output will not contain line breaks; if set to values >0, a newline will be inserted every lwidth*4 chars.

Definition at line 61 of file base64.h.

References lwidth.


Member Data Documentation

int Base64Encoder::lwidth [private]
 

Line width to use in 4-tuples; 0 for unlimited.

Definition at line 39 of file base64.h.

Referenced by Base64Encoder(), encode(), EncodedSize(), operator=(), and SetLWidth().

uint32 Base64Encoder::state [private]
 

Current encode state (carry).

Definition at line 38 of file base64.h.

Referenced by Base64Encoder(), encode(), operator=(), and reset().


The documentation for this class was generated from the following files:
Generated on Sat Feb 19 22:35:22 2005 for Ray by doxygen 1.3.5