本文介绍了PROTOBUFF INT64检查aganist以前输入的数据c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
message HealthOccurrenceCount
{
required int64 HealthID=1;
required int32 OccCount=2;
optional bytes wci=3;
}
我想根据 HealthID
;如果已经输入 HealthID
,那么代替只是递增现有条目的 OccCount
而不是添加新条目。
I would like to add data based on HealthID
; If HealthID
is already entered then instead of adding a new entry, the program should instead just increment the existing entry's 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
into string?
Is this code correct or I should convert HealthID
into string?
生成的代码:
// 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);
推荐答案
根据每个单数(必需或可选)字段有一个has_方法,如果该字段已设置,则返回true。
According to the doc there is a has_ methods for each singular (required or optional) field which return true if that field has been set.
您的代码将是:
HealthOccurrenceCount objHelthOccCount;
if(objHelthOccCount.has_healthid())
{
occCount++;
objHelthOccCount.set_occcount(occCount);
}
else
occCount = 1;
这篇关于PROTOBUFF INT64检查aganist以前输入的数据c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!