Views 4982 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
Why use protobuf?
Protocol buffers are a flexible, efficient, automated 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. As google puts it: “Protocol buffers are now Google’s lingua franca for data” and if it’s good enough for google, then it must be worth checking out!

We use protocol buffers to serialize persistant data for our IOS and Android games. Creating classes that persist data like shop, high scores, player preferences, achievements can be done in minutes with protobuf. And that why we ♥ protobuf!

This is not a protobuf usage tutorial, for that, you can check out the official documentation: https://developers.google.com/protocol-buffers/docs/overview. What you won’t find in the official documentation is how to make protobuf for iOS, and this is what this tutorial aims to explain. If you need to build protobuf for iOS, then read on :)


Protobuf build process in general for iOS:
I’ll show you how to build protobuf library for armv7, armv7s, and i386 architecture, then merge those libraries together into a single fat library that can be used in iOS projects. This library will work on the simulator as well as on the device.


Download protobuf
- We used protobuf2.4.1 (the last stable version at the time of writing) https://code.google.com/p/protobuf/downloads/list


Update command line tools in Xcode
(you are going to need the latest viersion)
- Command line tools can be updated by going to Xcode->Preferences.. then selecting the Downloads tab and selecting Command Line Tools


Build and install the protobuf compiler
- to convert protobuf files into source code, you will need a protobuf compiler! You can build and install this compiler by going to protobuf directory and executing the following commands:
$ ./configure
$ make
$ make check
$ make install


Build library for iOS
To build the ios protobuf static library
copy this script into protobuf directory and name it build-proto-ios.sh, then execute this to give the file execute privilegies:

$ chmod a+x ./build-proto-ios.sh
$ ./build-proto-ios.sh

Go make a cup of coffie, this will take a few minutes :) You can also download the precompiled fat ios library from here.

After the compilation is done you will see a new folder under protobuf root called: ios-build. This folder contains libprotobuf-lite.a. This is a static library for iOS.


Import library into Xcode
To import libprotobuf-lite.a into Xcode, just right click on a project directory where you want to import the library, from the drop-down list choose “Add Files to project-name…” and add libprotobuf-lite.a library.


Import headers into xcode
You still need to tell Xcode where to look for protobuf headers. To do this go to your project target build settings and under “Header Search Paths” add the path to protobuf-base-folder/src. The “protobuf-base-folder” being the folder in which you have the protobuf library from google.


The compiled protobuf library is the lite version so remember to put
option optimize_for = LITE_RUNTIME;
at the start of your proto definition file.

For a tutorial on how to use protobuf, it’s best to check out googles official documentation: https://developers.google.com/protocol-buffers/docs/overview

Happy protobuffing.

If you got any suggestions or question, feel free to ask/suggest!

[출처] http://www.giraffe-games.com/using-protobuf-protocol-buffers-on-iphone-ios/
[샘플] https://github.com/regwez/protobuf-objc-iOS5
?

List of Articles
No. Category Subject Author Date Views
773 Develop [c++] 기초강좌 #04(클래스) hooni 2003.04.23 11830
772 Develop JSON, BSON 변환 file hooni 2013.04.23 11814
771 Develop [ios] iOS In App Purchase 코드 부분 샘플 1 hooni 2013.11.20 11758
770 Develop [php] 배열 관련 함수 설명 ㅎㅎ hooni 2003.04.23 11746
769 Develop [php] whois정보 조회 프로그램 hooni 2003.04.23 11733
768 Develop [ios] UIWebView 쿠키 유지 hooni 2014.01.16 11704
767 Develop [vbs] CD롬 뱉는 스크립트.. hooni 2003.04.23 11699
766 System/OS [unix] 유닉스 csh에서 환경변수 등록 hooni 2003.04.23 11697
765 Develop [c++] String Tokenizer (나중에 c 코드로 변경해서 사용할 것) hooni 2013.04.23 11690
764 PPT [network] tcp/ip 설명 html파일 9장(ppt 포함) file hooni 2013.04.23 11650
763 System/OS php.ini 설정 안됐을때.. ㅋㅋ hooni 2013.04.23 11639
762 Develop [java] 초간단 싱글톤(Singleton) 패턴 샘플 코드 file hooni 2013.11.18 11593
761 Develop [php] 쉘에서 실행할 때 인수(파라미터) 받기.. hooni 2003.04.23 11588
760 Develop [c] 도스 공격(DoS Attack) 프로그램 file hooni 2013.04.23 11575
759 Develop [c] 시간 관련 함수 설명과 예제.. file hooni 2003.04.23 11523
758 Develop [c] home env stack overflow hooni 2003.04.23 11515
Board Pagination Prev 1 ... 24 25 26 27 28 ... 74 Next
/ 74