Protobuf詳解
按:
新公司前端后端肆饶,使用的數(shù)據(jù)化方式是protobuf (Protocol Buffer)。
一对人,什么是Protobuf
官方文檔給出的是:
a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more.
二涛舍,Protobuf的優(yōu)點(diǎn)
1,性能好箩言,效率高
2硬贯,代碼生成機(jī)制,數(shù)據(jù)解析類自動(dòng)生成
3陨收,支持向后兼容和向前兼容
4饭豹,支持多種編程語言(java,c++务漩,python)
5拄衰,參考文檔:http://blog.csdn.net/caisini_vc/article/details/5599468
三,Protobuf的缺點(diǎn)
1饵骨, 應(yīng)用不夠廣
2翘悉, 二進(jìn)制格式導(dǎo)致可讀性差(二進(jìn)制格式)
3, 缺乏自描述
官方文檔描述如下:for instance, protocol buffers would not be a good way to model a text-based document with markup (e.g. HTML), since you cannot easily interleave structure with text
4居触, 參考文檔:http://blog.csdn.net/caisini_vc/article/details/5599468
為什么要安裝protobuf
一般出現(xiàn)問題場(chǎng)景
1. Xcode編譯提示錯(cuò)誤:google/protobuf/stubs/common.h file not found
2. 終端執(zhí)行protoc --version 提示沒有安裝過
什么是protobuf
protobuf(Google Protocol Buffers)
Google提供一個(gè)具有高效的協(xié)議數(shù)據(jù)交換格式工具庫(類似Json)妖混。
但相比于Json,Protobuf有更高的轉(zhuǎn)化效率轮洋,時(shí)間效率和空間效率都是JSON的3-5倍制市。
怎么判斷有沒有安裝過protobuf?
終端中執(zhí)行:protoc --version
如何安裝
安裝protobuf-2.4.1
下載鏈接: vdisk.weibo.com/s/tYlk6JrNUYTY
安裝protobuf-2.5.0
下載鏈接: download.csdn.net/download/px_dn/7414673
下載完成后
第一步:
如果是2.4.1版本,在終端執(zhí)行:tar zxvf protobuf-2.4.1.tar.gz
如果是2.5.0版本,在終端執(zhí)行:tar zxvf protobuf-2.5.0.tar.gz
第二步:
如果是2.4.1版本,在終端執(zhí)行:cd protobuf-2.4.1
如果是2.5.0版本,在終端執(zhí)行:cd protobuf-2.5.0
第三步:
在終端執(zhí)行:./configure
第四步:
在終端執(zhí)行:make
第五步:
在終端執(zhí)行:make check
第六步:
在終端執(zhí)行:make install
以后六步執(zhí)行完成弊予,查看是否安裝成功
執(zhí)行命令:protoc --version
如果出現(xiàn)libprotoc 2.4.1或者libprotoc 2.5.0則說明安裝成功
如何卸載protobuf
在終端執(zhí)行
1. which protoc
注:whick protoc后會(huì)出現(xiàn)一個(gè)路徑祥楣,一般是 /usr/local/bin/protoc
這里默認(rèn)稱 /usr/local/bin/protoc為protoc_path
2. sudo rm 第一步中protoc_path
注:一般是sudo rm /usr/local/bin/protoc
即可完成卸載
可能會(huì)出現(xiàn)的問題
如果安裝的是2.4.1版本。
在安裝過程中,
執(zhí)行完第四步:make
如果出現(xiàn)
3 errors generated.
make[2]: *** [message.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
繼續(xù)執(zhí)行下去不會(huì)執(zhí)行成功
解決方案:
1. 打開protobuf-2.4.1/src/google/protobuf/message.cc文件
2. 添加 #include
然后關(guān)閉文件荣堰,重新執(zhí)行第四步:make 即可
本文出自
鏈接:http://mikewang.blog.51cto.com/3826268/1432136
鏈接:http://www.reibang.com/p/0a70eef1bd4a
著作權(quán)歸作者所有床未。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處振坚。