標籤:ios protocolbuf
使用的是 https://github.com/mingchen/protobuf-ios 首先是下載下來
它其中使用到得命令列
$ cd compiler$ ./autogen.sh$ ./configure$ make$ make install (optional)
The compiler is genrated at
src/protoc. 在src目錄下產生一個能夠將.proto檔案產生.m檔案的命令列工具protoc.
當然了,安裝的過程中遇到了好幾個問題需要先安裝brew,這個安裝的過程中,直接使用官方的安裝方法安裝就可以了,就是一句話,brew可以用來方便的安裝軟體
http://brew.sh https://github.com/Homebrew/homebrew
安裝,只要一個命令ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
安裝完了後,需要再安裝brew install automake
brew install autoconf並且,可能還會提示缺少libtool 使用命令 brew install libtool 安裝
安裝完後 ,執行最後make命令時候,還是會遇到 錯誤 [message.lo] Error 1,需要改動 檔案 message.cc
#include <google/protobuf/stubs/stl_util-inl.h>
+ #include <istream> (增加這一行)
使用方式 將一個 .proto檔案(名字叫Person.proto),例如如下的message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
放到 scr目錄下,然後,在src同級建立檔案夾 build/objc調用命令src/protoc --proto_path=src --objc_out=build/objc src/Person.proto 就會產生 Person.pb.h和Person.pb.m檔案兩個檔案了,這兩個檔案中,包含的就是 對應的oc對象了,
https://code.google.com/p/protobufeditor/ 這個是.proto的編輯工具
參考文檔 http://www.cnblogs.com/uniy/archive/2011/12/21/2296405.html
http://blog.csdn.net/hherima/article/details/17172441http://blog.csdn.net/hherima/article/details/21534673https://gist.github.com/BennettSmith/7150245
MAC/IOS中使用protocolBuf