BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balxml_base64parser

Detailed Description

Outline

Purpose

Provide push parser for Base64 types.

Deprecated:
Use bdlde_base64decoder instead.

Classes

Description

The balxml::Base64Parser class template provided by this component can be used to parse Base64 characters into one of the supported Base64 types, which are bsl::vector<char> and bsl::string. The TYPE parameter can be one of these two types.

This class template is a model of the PushParser concept, which contains the following methods:

int beginParse(TYPE *object);
// Prepare the parser to start parsing a new value and associate the
// specified 'object' with the parser. Return 0 if successful and
// non-zero otherwise.
int endParse();
// Ends the parse operation and store the value parsed from the pushed
// characters into the associated object. Return 0 if successful and
// non-zero otherwise. The behavior is undefined unless an object is
// associated with this parser. Upon successful completion, the parser
// will be disassociated with the object.
template <typename INPUT_ITERATOR>
int pushCharacters(INPUT_ITERATOR begin, INPUT_ITERATOR end);
// Push the characters ranging from the specified 'begin' up to (but
// not including) the specified 'end' into this parser. Return 0 if
// successful and non-zero otherwise. The parameterized
// 'INPUT_ITERATOR' must be dereferenceable to a 'char' value. The
// behavior is undefined unless an object is associated with this
// parser.

Usage

The following snippets of code illustrate the usage of this component. Suppose you had an input stream that contained Base64 data. The following loadFromBase64Stream function loads this data into an bsl::vector<char> blob:

#include <istream>
#include <iterator>
#include <vector>
using namespace BloombergLP;
int loadFromBase64Stream(bsl::vector<char> *result, bsl::istream& stream)
{
enum { FAILURE = -1 };
if (0 != parser.beginParse(result)) {
return FAILURE;
}
if (0 != parser.pushCharacters(bsl::istreambuf_iterator<char>(stream),
bsl::istreambuf_iterator<char>())) {
return FAILURE;
}
return parser.endParse();
}
Definition balxml_base64parser.h:161
int pushCharacters(INPUT_ITERATOR begin, INPUT_ITERATOR end)
Definition balxml_base64parser.h:264
int beginParse(TYPE *object)
Definition balxml_base64parser.h:226
int endParse()
Definition balxml_base64parser.h:241
Definition bslstl_vector.h:1025

The following function demonstrates the loadFromBase64Stream function:

#include <sstream>
void usageExample()
{
const char INPUT[] = "YWJjZA=="; // "abcd" in Base64
bsl::istringstream iss(INPUT);
int result = loadFromBase64Stream(&vec, iss);
assert(0 == result);
assert(4 == vec.size());
assert('a' == vec[0]);
assert('b' == vec[1]);
assert('c' == vec[2]);
assert('d' == vec[3]);
}
Definition bslstl_istringstream.h:176
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this vector.
Definition bslstl_vector.h:2664