【问题标题】:Check and add data into protobuff using C++使用 C++ 检查并将数据添加到 protobuff
【发布时间】:2015-08-24 07:55:45
【问题描述】:
message HealthOccurrenceCount
{
    required int64 HealthID=1; 
    required int32 OccCount=2; 
    optional bytes wci=3;
}

我想根据HealthID添加数据;如果已经输入了HealthID,那么程序应该只增加现有条目的OccCount,而不是添加新条目。

HealthOccurrenceCount objHelthOccCount;
if(objHelthOccCount.healthid() == healthID) // Is this right or do I need to iterate all the nodes?
{
    occCount++;  
    objHelthOccCount.set_occcount(occCount);  
}
else       
    occCount = 1;   

这段代码是否正确,或者我应该将HealthID 转换为字符串?

生成的代码:

// required int64 HealthID = 1;
inline bool has_healthid() const;
inline void clear_healthid();
static const int kHealthIDFieldNumber = 1;
inline ::google::protobuf::int64 healthid() const;
inline void set_healthid(::google::protobuf::int64 value);

【问题讨论】:

标签: c++ visual-c++ protocol-buffers protobuf-net protobuf-csharp-port


【解决方案1】:
HealthOccurrenceCount objHelthOccCount;
if(objHelthOccCount.has_healthid())
{
    occCount++;  
    objHelthOccCount.set_occcount(occCount);  
}
else       
    occCount = 1;   

【讨论】:

    猜你喜欢
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多