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.
好文章一:
"
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 =