mac安装protobuf

mac安装protobuf
首先从http://code.google.com/p/protobuf/下载protobuf


之后需要安装brew
[非root]
brew install autoconf[need to across the great wall and reach the bigger world]
brew install automake
brew install libel
[root]
sudo ./autogen.sh
./configure(先autogen.sh才有,如果没有权限chmod +x configure)
make
make check
make install


protoc —version
显示结果:
sh-3.2# protoc --version
libprotoc 3.0.0


首先手写一个proto文件,然后放在make成功的src文件夹下,看到了闪闪发光的protoc,那就是来编译源proto称为目标文件的编译器。建立文件夹,来存放准备编译的proto文件,不过似乎要放在src的目录下面,否则似乎会出问题。。。按照参考资料的教程来就没问题。
其中ptotoc的参数:
-I(—proto_path) = $SRC_DIR也就是src的绝对路径
—cpp_out = …输出的路径
最后是要编译的proto的绝对路径。




参考资料:
比较好的8、9、3、11


1.protobuf安装
http://blog.csdn.net/yohunl/article/details/41797621


2.遇到问题:
[libprotobuf WARNING google/protobuf/compiler/parser.cc:547] No syntax specified for the proto file: yzh-proto/yzh.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)


http://stackoverflow.com/questions/27958571/serializing-part-of-a-message-with-protobuf


解决方法:在proto的最前面加上syntax = “proto2”


3.一个比较全面的介绍from IBM developer


4.object c
http://www.cnblogs.com/uniy/archive/2011/12/21/2296405.html
http://www.kelvinkaodev.com/blog/2010/08/compiling-the-protocol-buffer-compiler-for-objective-c/


5.mac + protobuf
http://blog.csdn.net/yohunl/article/details/41797621


6. mac上用于编译Google Protobuf 2.5.0 for Xcode5.0/iOS7的脚本
http://blog.csdn.net/hherima/article/details/17172441


7.一个自动安装的脚本
https://gist.github.com/BennettSmith/7150245


8.使用和编码
http://blog.csdn.net/hherima/article/details/21534673


9.Google Protobuf开发指南 很是全面的介绍
http://my.oschina.net/macwe/blog/157862?fromerr=dTsRN7pl


个人认为最有用的部分
protobuf在网络通信中应用
Protobuf在TCP中使用注意事项
我的测试程序使用的TCP,于是一个很自然的问题,报文的边界或者报文长度问题,在网上google了一圈之后发现这个确实是个问题,解决问题的方案也很直接,在报文前面加上一个字段表示整个报文的长度(包括加上的字段)。




bool SerializeToArray(void * data, int size) const


bool SerializeToString(string * output) const


当然还有一些其他变种,我不喜欢使用stl string,所以选用了SerializeToArray


 


可以使用一下API反序列化:


boolParseFromArray(const void * data, int size)


boolParseFromString(const string & data)


以上写着函数都定义在  google/protobuf/message_lite.h 中




10.google protobuf代码风格
https://developers.google.com/protocol-buffers/docs/style#message-and-field-names


11.github 官方
https://github.com/google/protobuf


12.third party add ones和google无关但是使用了protobuf技术的项目
Third Party Add ons

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值