https://developers.google.cn/protocol-buffers/docs/proto3 //官方文档
https://www.cnblogs.com/autyinjing/p/6495103.html //proto2
https://www.cnblogs.com/tohxyblog/p/8974763.html //proto3
protoc为message的每个required字段和optional字段都定义了以下几个函数(不限于这几个)
TypeName xxx() const; //获取字段的值
bool has_xxx(); //判断是否设值
void set_xxx(const TypeName&); //设值
void clear_xxx(); //使其变为默认值
void useXXX() //set_XXX 的值是多少
为每个repeated字段定义了以下几个:
TypeName* add_xxx(); //增加结点
TypeName xxx(int) const; //获取指定序号的结点,类似于C++的"[]"运算符
TypeName* mutable_xxx(int); //类似于上一个,但是获取的是指针
int xxx_size(); //获取结点的数量
另外,下面几个是常用的序列化函数:
1 bool SerializeToOstream(std::ostream * output) const; //输出到输出流中
2 bool SerializeToString(string * output) const; //输出到string
3 bool SerializeToArray(void * data, int size) const; //输出到字节流
与之对应的反序列化函数:
1 bool ParseFromIstream(std::istream * input); //从输入流解析
2 bool ParseFromString(const string & data); //从string解析
3 bool ParseFromArray(const void * data, int size); //从字节流解析
其他常用的函数:
1 bool IsInitialized(); //检查是否所有required字段都被设值
2 size_t ByteSize() const; //获取二进制字节序的大小```