thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lehmann, Thomas" <thomas.lehm...@adtech.com>
Subject enum with thrift
Date Tue, 20 Jan 2015 08:00:55 GMT
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



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message