4

not sure if i am just using it wrong because this is not really my field of expertise but i was under the impression that this should give me a complete decoded openframeworks buffer (or a simple string, i tried various ways all resulting in the same too short string):

string str; // string is a line from a file handle and shows to be ok in the debugger
istringstream istr(str);
Poco::Base64Decoder b64in(istr);
ofBuffer buffer;
b64in >> buffer;

now an example base64 string i am decoding is this line:

I2J1bmRsZQAAAAAAAAAAAQAAABwvT1NDL1NwYWNlSW50ZW5zaXR5ACxmAAA6nUlSAAAAFC9PU0MvU3BlZWQAACxmAAA90/fPAAAAGC9PU0MvU21vb3RobmVzcwAsZgAAP2Wu5gAAABQvT1NDL1JlYWNoAAAsZgAAPnxQSAAAABgvT1NDL0RlbnNpdHkAAAAALGYAAAAAAAAAAAAYL09TQy9Db2hlcmVuY2UAACxmAAA+tYEGAAAAIC9PU0MvVHJhdmVsSW50ZW5zaXR5AAAAACxmAAA8eQlsAAAAFC9PU0MvUmh5dGhtACxmAAA+6LQ5AAAAGC9PU0MvSGFybW9ueQAAAAAsZgAAPui0OQAAABQvT1NDL0VuZXJneQAsZgAAPYznBA==

the line does not resolve to a simple ascii text but rather a raw osc packet dumped in base64 by some vvvv patch i do not have access to... so i guess it could also be an encoding issue?

and all i get in the output, no matter if i use a streamcopier or an operator like above, is only "#bundle". could this somehow be related to the / character or other non-standard stuff following the "#bundle"? i was under the impression that the Base64Decoder doesn't care about whitespace or whatever it finds in the decoded data.

DasAntonym
  • 452
  • 3
  • 19
  • 1
    `std::string` is not a byte buffer! It actually cares about things like NULL characters and control characters. – Sebastian Hoffmann Mar 03 '14 at 16:22
  • 1
    @Paranaix - std::string can store control characters. The problem is that it can only do that if the programmer explicitly used string::append(), or constructing the string using the two argument constructor that takes a char* and an integer. – PaulMcKenzie Mar 03 '14 at 16:26
  • thanks for the speedy comments. but here i am using a byte buffer so only the input line is a string. i was thinking that the output of the base64decoder shouldn't care about whitespace and just return all chars no matter what they actually represent. what other way is there to retrieve the contents of the base64decoder? the streamcopier from poco returned the same result. – DasAntonym Mar 03 '14 at 16:28
  • 1
    @DasAntonym - Did you inspect the string by using the debugger? How do you know that the string is the problem instead of operator >> being the problem? You need to inspect the string carefully yourself -- don't introduce other functions (such as operator >>) that can give you a false positive (or negative) indication. – PaulMcKenzie Mar 03 '14 at 16:30
  • thank you paul, i didn't look closely enough. it seems to me that the string always gets truncated after 100 characters so the string is NOT exactly the line i have in the file. but then again, these 100 first characters decode to more chars then my output ("#bundle") when using a web based base64 decoder... – DasAntonym Mar 03 '14 at 16:41
  • correction: the string is not truncated, it's actually the complete line, that was just the summary in the debugger. i guess i am just not fit enough in c++ to deal correctly with streams. i'll have to do more reading on how to get the result from the decoder. thanks for your help. – DasAntonym Mar 03 '14 at 16:55

2 Answers2

7

so i ended up not using the operator but rather copying the output of the base64decoder to a stream and then getting a string from that:

istringstream istr(str);
ostringstream ostr;
Poco::Base64Decoder b64in(istr);
copy(std::istreambuf_iterator<char>(b64in),
    std::istreambuf_iterator<char>(),
    std::ostreambuf_iterator<char>(ostr));
cout << ostr.str(); // returns full decoded output
DasAntonym
  • 452
  • 3
  • 19
  • Tip when exception thrown: check maybe you need to create `Poco::Base64Decoder` like: `Poco::Base64Decoder decoder{istr, Poco::BASE64_URL_ENCODING};` – Gelldur Aug 26 '21 at 12:30
3

This has actually nothing to do with Poco::Base64Decoder. The stream extraction operator for std::string will stop at the first whitespace character it encounters in your input stream (which in case of Base64Decoder would be the decoded data).

Günter Obiltschnig
  • 1,536
  • 11
  • 13