Protobuf

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; //获取二进制字节序的大小```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值