Union is built on top of struct. Some impls may still write all the fields,
however this is not necessary.
________________________________
Von: Lehmann, Thomas
Gesendet: 20.01.2015 09:05
An: [email protected]
Betreff: enum with thrift
Hi,
take a definition like here (using thrift 0.9.0):
enum parameter_type {
STRING = 0,
INTEGER = 1
}
union request_parameter_value {
1: string string_value,
2: i64 integer_value
}
struct request_parameter {
1: parameter_type type = 0,
2: request_parameter_value value
}
I'm wondering ... maybe I misunderstand the generated code ...
It look like that ALL values inside the union are written;
In C/C++ I expected that one of these value is written only (union).
Right?
uint32_t request_parameter_value::write(::apache::thrift::protocol::TProtocol*
oprot) const {
uint32_t xfer = 0;
xfer += oprot->writeStructBegin("request_parameter_value");
xfer += oprot->writeFieldBegin("string_value",
::apache::thrift::protocol::T_STRING, 1);
xfer += oprot->writeString(this->string_value);
xfer += oprot->writeFieldEnd();
xfer += oprot->writeFieldBegin("integer_value",
::apache::thrift::protocol::T_I64, 2);
xfer += oprot->writeI64(this->integer_value);
xfer += oprot->writeFieldEnd();
xfer += oprot->writeFieldStop();
xfer += oprot->writeStructEnd();
return xfer;
}
Regards,
Thomas