Google Protocol buffer 系列二: 常用api

本文介绍了Google Protocol Buffers的基础知识,包括什么是Protocol Buffers、C++中的基本使用,如序列化和反序列化操作。同时,文章提到了如何处理repeated和嵌套message字段,并给出相关代码示例。此外,还提及了编译接口文件的方法和解决编译中遇到的问题。
摘要由CSDN通过智能技术生成


What Are Protocol Buffers?

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages – Java, C++, or Python.


Protocol Buffer Basics: C++


 a mutable_ getter that lets you get a direct pointer to the string, and an extra setter. Note that you can call mutable_email() even if email is not already set; it will be initialized to an empty string automatically. If you had a singular message field in this example, it would also have a mutable_ method but not a set_ method.


好文章一:

Protocol Buffers十分钟上手:入门示例

"

  4.编译接口文件

  调用protoc编译器进行编译:protoc x.proto –cpp_out=./oo,请注意需要指出输出文件,C++语言使用–cpp_out指出,其它语言可以查看帮助protoc –help,输出目录oo是必须事先创建好的,否则会报输出目录下存在。

  编译成功后,将在oo目录下生成供应用调用的文件x.pb.h和x.pb.cc,编译自己代码的时候应当将x.pb.cc包含进去。

"

"

 p.SerializeToString(&str); // 将对象序列化到字符串,除此外还可以序列化到fstream等

  printf(”%s\n”, str.c_str());

  Person x;

  x.ParseFromString(str); // 从字符串反序列化

  printf(”x.name=%s\n”, x.name().c_str()); // 这里的输出将是tom,说明反序列化正确

  return 0;

"


好文章二:



[IBM DW] Google Protocol Buffer 的使用和原理


原理讲解!!!


***********************************************************************************************************************************************

如何访问、赋值 类似 vector的repeated 元素?


Here's a snippet of my PB (detail ommited for brevity):

message DemandSummary
{
   
    required uint32 solutionIndex     = 1;
    required uint32 demandID          = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值