PROTOBUF INT64 检查先前输入的数据 c++
PROTOBUFF INT64 check aganist previously entered data c++
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);
根据 doc,每个单数(必填或可选)字段都有一个 has_ 方法,如果已设置该字段,则 return 为真。
您的代码将类似于:
HealthOccurrenceCount objHelthOccCount;
if(objHelthOccCount.has_healthid())
{
occCount++;
objHelthOccCount.set_occcount(occCount);
}
else
occCount = 1;
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);
根据 doc,每个单数(必填或可选)字段都有一个 has_ 方法,如果已设置该字段,则 return 为真。
您的代码将类似于:
HealthOccurrenceCount objHelthOccCount;
if(objHelthOccCount.has_healthid())
{
occCount++;
objHelthOccCount.set_occcount(occCount);
}
else
occCount = 1;