Best way to send binary data using Thrift

I have a structure in C ++ where such bytes are stored:

struct RemoteData { /// some other fields here unsigned char* buf; int bufLen; }; 

And I need to send this data to a remote service written in C ++ through thrift. I found three ways to map this structure to economical idl:

  • Using container types, such as:

     struct RemoteData { 1: list<BYTE> buf, ... } 
  • Using binary type:

     struct RemoteData { 1: binary buf, ... } 
  • Saving data to string :

     struct RemoteData { 1: string buf, ... } 

What is the best way?

+7
source share
1 answer

The value contained in the thrift style string must be encoded in UTF8, otherwise any client will not be able to read it (for example, the Java client client).

The Thrift list<byte> will be converted to std::vector<int8_t> in C ++, but in other languages ​​it will not be very good (for example, in java it will be compiled into a suboptimal list<byte> .

The binary type is the best choice in terms of interacting with clients in other languages ​​and the correct definition of the protocol.

Since all 3 definitions produce messages of about the same size, I would go with binary : even if you do not need compatibility with other languages ​​now, you may need this in the future.

+12
source

All Articles