std::stringstream o; typedef std::ostreambuf_iterator<char> o_iter; base64_t::decoder<o_iter> deciter(o_iter(o)); *std::copy(std::istreambuf_iterator<char>(o), std::istreambuf_iterator<char>(), deciter).eof().first=0;
x::base64::decoder
is the comparable decoding output iterator.
x::base64::decoder
's template parameter is
an output iterator class.
x::base64::decoder
expects
to receive a
base64
-encoded sequence, which gets decoded and
written to the output iterator class instance that's passed to
x::base64::decoder
's constructor.
Its eof
() decodes any partially-received
encoded sequence, then returns a std::pair
.
first
is the final value of the output iterator
originally given to the constructor.
second
is a bool
which is
true
if the sequence was decoded with no errors, or
false
if the sequence contained any characters not
a part of the base64
alphabet (excepting
CR
and LF
).
size_t needed=base64_t::decoded_size(buffer.size());
decoded_size
() estimates the size of a decoded
base64
sequence, given the size of the encoded
sequence.
decoded_size
() returns an upper estimate. The
exact size cannot be known until the entire sequence gets decoded, because
it depends on the presence of any padding characters or newlines.
The value returned by decoded_size
() is an upper
estimate, for a buffer large enough to hold the largest possible
decoded sequence from an encoded sequence of the given size.
auto res=base64_t::decode(buffer.begin(), buffer.end(), iter); iter=res.first;
This is a convenience function that takes a pair of iterators, a beginning
iterator, and an ending iterator for a
base64
-encoded sequence; and an output iterator.
decode
() constructs a
x::base64::decoder
using the output iterator passed as the third parameter,
iterates over the input sequence, passing it to the instantiated
x::base64::decoder
,
then invokes its eof
() and returns the new output
iterator and an indication whether the sequence was valid and did not
contain characters other than those in the base64
alphabet.
This example base64
-decodes the
buffer
container into the iter
output iterator, then updating it with the new iterator value.