MAC/IOS中使用protocolBuf

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.