【问题标题】:How do I set fields in Thrift struct properly in C++ sources?如何在 C++ 源代码中正确设置 Thrift 结构中的字段?
【发布时间】:2015-08-19 06:12:40
【问题描述】:

我注意到在我的 thrift 结构 MyThriftStruct 生成的 C++ 类 MyThriftStruct 中有一个名为 __set_FIELD 的方法。调用此方法会将属性 MyThriftStruct.__is_set.FIELD 设置为 true,这会告知已设置此字段的结构。

我还注意到,在official tutorial 中,他们通过直接复制值来设置 thrift 结构的字段:

MyThriftStruct.FIELD = val;

第一种方法看起来很难看,但后一种方法并没有改变__isset 标志。那么我应该使用哪一个来设置 C++ 中 thrift struct 的字段呢?

【问题讨论】:

    标签: c++ thrift


    【解决方案1】:

    这取决于:对于required 字段或default(既非必需也非可选)字段MyThriftStruct.FIELD = val; 就足够了。

    set_FIELD 仅用于可选字段(或需要手动修改__isset struct 字段以确保可选字段序列化)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 1970-01-01
      • 2021-06-14
      • 2015-10-02
      • 1970-01-01
      相关资源
      最近更新 更多