mardi 30 mars 2021

basic_streambuf

We have a file which is present in a data store (S3) which contains data in the form of byte[] (uploaded using Java language).

Now when i download the file, the data i get is in the form of std::basic_streambuf (Ideally it should also be having bytes). Now i want to send this data to another API which takes uint8_t* as the input.

What is the way to do so? Is it making any sense to even do that?

I tried this:


// Assume streambuf is:
std::streambuf *buf;

std::stringstream ss;
ss << buf;

// Solution1
const std::string output1 = ss.str(); 
cout<<output1;
// This prints the whole data with some weird characters (i think weird characters are valid because data is in byte form). Upon converting output1 to uint8_t*, the final data contains only 20 characters/bytes.

// Solution2
uint8_t* finalString;
ss >> finalString;
cout<<finalString;
// This prints only initial 20 characters/bytes and the remaining part is skipped.

So with both Solution1 and Solution2, ultimate goal of getting uint8_t* of full data could not be achieved. What is the suggested way to do so?

Aucun commentaire:

Enregistrer un commentaire