Creating a binary (custom length) string in C ++

I use the Apache Thrift RPC mechanism (compiled in C ++) to communicate with Apache Flume. I have to use the specific API that this platform provides.
I want to send binary data, but the RPC function only accepts std :: string as a parameter. And because of this, I can only send this binary data that appears before the first occurrence 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 for the source code and the function str.data () I called in (uint8_t *) and sends 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” and uint8_t as data and given length? It is even possible to create a representation in memory of my own string with the desired binary data.

+5
source share

Source: https://habr.com/ru/post/1231958/


All Articles