Need some help with Base64DecoderBuf

Please post support and help requests here.
asphalttechnician
Posts: 2
Joined: 24 Apr 2013, 19:15

Need some help with Base64DecoderBuf

Postby asphalttechnician » 24 Apr 2013, 19:37

Hi,

I am new to using Poco and I am having some trouble with using Base64EncoderBuf. I was originally using Base64Encoder which was working for me, but I want to get rid of the new line characters that get inserted and it look like you need to use Base64EncoderBuf, calling setLineLength(). It was working when I had the following...

Code: Select all

std::string myString("mystring");
std::istringstream iStrStream(myString);
std::ostringstream oStrStream;
Poco::Base64Encoder encoded(oStrStream);
std::copy(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(encoded));
encoded.close();


I tried replaced Base64Encoder with Base64EncoderBuf, but I can no longer use the std::ostreambuf_iterator in the std::copy() method (inheritance between two different Base64Encoder classes is different). I can't seem to find an appropriate iterator to get this to work. Could someone point me in the right direction? It's possible I can no longer use it this way, so any pointers would be greatly appreciated. I've looked around and I couldn't find any examples using the Base64EncoderBuf class, only the Base64Encoder class.

Thanks for the help.

guenter
Posts: 1186
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Need some help with Base64DecoderBuf

Postby guenter » 24 Apr 2013, 22:04

rdbuf() is your friend:

Code: Select all

std::string myString("mystring");
std::istringstream iStrStream(myString);
std::ostringstream oStrStream;
Poco::Base64Encoder encoded(oStrStream);
encoded.rdbuf()->setLineLength(0);
std::copy(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(encoded));
encoded.close();

asphalttechnician
Posts: 2
Joined: 24 Apr 2013, 19:15

Re: Need some help with Base64EncoderBuf

Postby asphalttechnician » 24 Apr 2013, 23:14

I knew I had to be missing something that was straightforward. This does exactly what I need. Thank you for your reply!

In case someone may find this useful, prior to getting an answer I just decided to strip out the characters before returning the string to the requester. Using my original code sample, I performed the following post-processing:

Code: Select all

   struct RemoveLTS
   {
      bool operator()(char c) const { return c == '\n' || c == '\r'; }
   };

   std::istringstream iStr(oStrStream.str());
   std::ostringstream oStr;
   std::remove_copy_if(std::istreambuf_iterator<char>(iStr), std::istreambuf_iterator<char>(), std::ostreambuf_iterator<char>(oStr), RemoveLTS());


The best way though is of course not to have the characters added to the encoded stream in the first place so that additional processing is not required.


Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest

cron