|
Boost : |
Subject: Re: [boost] Is Boost interested in the Boost-based Base64 library
From: Alexander Arhipenko (arhipjan_at_[hidden])
Date: 2011-06-15 05:16:56
On Thu, Jun 9, 2011 at 9:43 PM, Denis Shevchenko
<for.dshevchenko_at_[hidden]> wrote:
> Hi all!
>
> Not so long ago I was looking for a solution to Base64 encoding/decoding.
>
> In this page -
> http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/dataflow.html -
> I found example of such solution, with 'base64_from_binary' and
> 'transform_width' iteartors. But it is just a "blank", not ready-to-use
> solution.
>
> I created solution. But I definitely know many developers looking for a
> simple, ready-to-use, header-only and 'real C++' solution for Base64. So I
> want to offer you such solution.
>
> Some examples:
>
> int main() {
> std::string my_text = "My text for encoding!";
> std::string encoded_text = boost::base64().encode( my_text );
> std::string my_text_again = boost::base64().decode< std::string >(
> encoded );
> }
>
> For binary data:
>
> int main() {
> typedef std::vector< unsigned char > binary_string;
>
> binary_string my_bin = list_of( 0xFF )( 0xAA )( 0x01 );
> std::string encoded_bin = boost::base64().encode( my_bin );
> binary_string my_bin_again = boost::base64().decode< binary_string >(
> encoded );
> }
>
> For streams:
>
> int main() {
> boost::filesystem::ifstream my_jpeg( "/some/path/to/my/image" );
> // fstream checking omitted...
>
> std::string encoded_jpeg = boost::base64().encode( my_jpeg );
>
> boost::filesystem::ofstream my_jpeg_again( "/some/path/to/decoded/image"
> );
> // fstream checking omitted...
>
> boost::base64().decode( encoded_jpeg, my_jpeg_again );
> }
>
> This is first variant. IMHO such solution will be useful for Boost users.
>
> What you think about it?
>
> - Denis
>
Hi Denis!
I think having base64 stuff in boost utilities would be very useful.
But I think interfaces that you are providing is very high-level.
I've implemented base64_encode some time ago and it had
the following interface:
template <class InIt, class OutIt>
OutIt base64_encode(InIt f, InIt l, OutIt out);
I suppose your 'encode' interfaces could me implemented via function above.
Also pay attention that there are not only std::string and std::istream/ostream
in the world. E.g., one would possibly like to encode QString.
Another comment is performance. For most applications this could be crucial.
Could you please provide the sources in order
we could compare our home-bred solution to yours?
Do you have any optimizations for random access ranges/iterators/containers?
Or do you assume that input parameter (string/range/container/whatever)
could be always accessed randomly?
Regards
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk