包含如下内容:
- set_allocated_xxx()
- mutable_xxx()
- set_xxx()
- has_xxx()
函数的用法:
package LIFE;
message fakeFace{
uint32 height = 1;
uint32 width = 2;
eyes hereye = 3;
}
message eyes{
bool ifgood = 1;
uint32 length = 2;
}
message myGirl{
string name = 1;
uint32 age = 2;
repeated fakeFace faces = 3;
}
using namespace LIFE;
myGirl tmp_mG;
//has_xxx 用于判断是否存在此变量,返回true or false,这里因为刚创建所以肯定返回false
if(!tmp_mG.has_faces())
{
fakeFace *tmpfake1 = tmp_mG.add_faces();
}
tmpfake->set_height(111);
tmpfake->set_width(123);
eyes *tmp_eye = tmpfake->mutable_hereye();
tmp_eye->set_ifgood(true);
tmp_eye->set_length(3);
或者
eye *tmp_eye = new eye;
tmp_eye->set_ifgood(true);
tmp_eye->set_length(3);
tmpfake->set_allocated_hereye(tmp_eye);
//mutable_xxx 也可以用于直接取变量
tmp_eye->ifgood(); //取值 ifgood