5

I am using Apache Thrift RPC (Compiled to C++) mechanism to communicate with Apache Flume. I have to use specific API that this platform supplies.
I want to send binary data, But the RPC function accepts only std::string as a parameter. And because of that I only able to send that binary data that comes before the first appearance of 0x00.

u_char bin[10] = {'a','b',1,'d','e',0,'2','3','4','5'};
// Takes only the first 5 bytes, and sets a length of 5
string art_test((const char *)bin);

I searched through the source code and the function I call casts the str.data() into (uint8_t*) and sends the data of length str.size().

uint32_t ssize = static_cast<uint32_t>(str.size());
trans_->write((uint8_t*)str.data(), ssize);

Is there a way to create a 'binary string', with uint8_t as a data and with specified length? Maybe even create the in memory representation of string of my own with the desired binary data.

Rtik88
  • 1,777
  • 2
  • 11
  • 13
  • 3
    Actually, you can embed a null character in a `std::string`, it's not a c string http://stackoverflow.com/questions/164168/how-do-you-construct-a-stdstring-with-an-embedded-null – StoryTeller - Unslander Monica Sep 21 '15 at 15:28
  • 1
    Thank you @StoryTeller that seems to solve the problem! The length field in the constructor is quite useful :-) – Rtik88 Sep 21 '15 at 15:33

0 Answers0