I have a structure in c++ which stores bytes like this:
struct RemoteData
{
/// some other fields here
unsigned char* buf;
int bufLen;
};
And I need to send this data to remote service, written in C++, via thrift. I found three ways how to map this structure to thrift idl:
-
Using container types like this:
struct RemoteData { 1: list<BYTE> buf, ... } -
Using
binarytype:struct RemoteData { 1: binary buf, ... } -
Storing data in
stringtype:struct RemoteData { 1: string buf, ... }
What is the best way?
The value contained in thrift
stringtype must be UTF8-encoded, otherwise some client won’t be able to read it (Java thrift client for example).Thrift
list<byte>type will be converted intostd::vector<int8_t>in c++, but in other languages it will be not so good (for example, in java it will be compiled into suboptimalList<Byte>.The
binarytype is the best choice in terms of interoperability with clients in other languages and the correctness of protocol definition.Since all 3 definitions produce messages of roughly the same size, I’d go with
binary: even if you don’t need interoperability with other languages now, you may need it in future.