protobuf net怎么在iOS中实用

Using protobuf (Protocol Buffers) on iPhone (iOS)
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: /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) /p/protobuf/downloads/list
Update command line tools in Xcode (you are going to need the latest version)
- 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 check
$ make install
Build library for iOS
To build the ios protobuf static library
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 .
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: /protocol-buffers/docs/overview
Happy protobuffing.
If you got any suggestions or question, feel free to ask/suggest!
This site uses cookiesOkay, thanksprotobuf 怎么在iOS中实用_百度知道
protobuf 怎么在iOS中实用
提问者采纳
命令是;目录下寻找名为”protoc-gen-objc”的插件;bin&#47:  test.txt安装,一是直接使用C++版.pb,项目根目录下将会出现Classes目录:  1;&#47,说明ProtocoBuffer Compiler for Objective-C可以正常工作了,使用  将步骤3中编译输出的test.h和dylib就可以了.proto文件,并使用该插件编译,但是在5以下的32位上编译环不容易弄对。  5。  git clone https,最终生成两个文件:  ;local/Classes目录导入到Xcode项目中,下载ProtocolBuffer包。导入完毕后.3;autogen,测试.pb,选中”Copy items into destination group‘s folder(if needed)“;local&#47。com/github.m  这个步骤通过后,并执行;local&#47.pb.2做修改, 引用,并按照包中根目录下README;usr&#47,将项目根目录“.sh  。  目前有两种类型的实现。  3.”添加到头文件搜索路径中去;configure  make  make install  最终生成的插件名字为protoc-gen-objc,会生成编译器protoc.3推出的plugin模式编写插件.proto文件编译器(protoc)支持Objective-C类型的文件输出;src/Header Search Pathes”:&#47。进入该目录, 用在64位的5s上很容易.h  test.proto  protoc会自动在&#47:  mv Classes ProtocolBuffers  修改项目属性中”Build Setting——&bin目录下。  make install后;Directory/runtime/ test.pb。将该目录改名为ProtocolBuffers(注意最后的s).h和protobuf-bin&#47,导入时,会被安装到&#47。  二是用objc版的。  另一个针对ProtocolBuffer2.1中使用ProtocolBuffer  将步骤2中protobuf-obj&#47  有两种方式.git  默认会在当前运行目录下创建protobuf-objc目录,在Xcode4。可以参考如下操作。  我选用第二种方式.m添加到项目中,下载Objective-C compiler for ProtocolBusr/目录下;booyah&#47。  4,以插件方式支持Objective-C类型的文件输出.proto文件.&#47。  2;Output&#47,并拷贝到&#47:  protoc –objc_out=&#47.&#47.proto文件编译,就可以直接使用了。  随便写一个test。  这样ProtocolBuffer for Objective-C的工作环境就配置好了,这也是Google推荐的方式。  导入位置选择项目根目录。  一个针对ProtocolBuffer2;usr&#47,并编译该文件,使最后生成的
资深电脑人
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁protobuf 怎么在iOS中实用_百度知道
protobuf 怎么在iOS中实用
提问者采纳
google:&#47.3推出的plugin模式编写插件。  3:https.h和test,并按照包中根目录下README;protobuf-Header Search Pathes”。命令是;runtime&#47,但是在5以下的32位上编译环不容易弄对。  5、com/Output&#47.”添加到头文件搜索路径中去。  这样ProtocolBuffer for Objective-C的工作环境就配置好了,会被安装到&#47。导入完毕后;booyah&#47.pb,并执行:/目录下, 用在64位的5s上很容易:&#47.git  默认会在当前运行目录下创建protobuf-objc目录.proto文件  有两种方式; test:  1,项目根目录下将会出现Classes目录;ProtocolBuffers  另一个针对ProtocolBuffer2.proto文件编译;目录下寻找名为”protoc-gen-objc”的插件,并编译该文件,说明ProtocoBuffer Compiler for Objective-C可以正常工作了。  2:http,下载Objective-C compiler for ProtocolBDirectory&#47,下载ProtocolBuffer包;bin&#47。  二是用objc版的。  一个针对ProtocolBuffer2.&#47.proto文件。将该目录改名为ProtocolBuffers(注意最后的s), 引用;bin&#47.3.h  test.proto文件编译器(protoc)支持Objective-C类型的文件输出;&#47。  git clone https,将项目根目录“;local&#47。  它在这里.&#47.github,并使用该插件编译;local&#47。  目前有两种类型的实现;configure  make  make install  最终生成的插件名字为protoc-gen-objc,导入时;usr&#47、com/booyah&#47.h和dylib就可以了.proto  protoc会自动在&#47,并拷贝到&#47:  mv Classes ProtocolBuffers  修改项目属性中”Build Setting——&bin目录下;p&#47。  它在这里、com/usr&#47。  make install后。可以参考如下操作;src&#47,这也是Google推荐的方式,测试,使用  将步骤3中编译输出的Classes目录导入到Xcode项目中.&#47.m  这个步骤通过后。  4;protobuf-objc  我选用第二种方式.sh  .pb。  随便写一个test.txt安装;&#47,以插件方式支持Objective-C类型的文件输出:  metasyntactic&#47,会生成编译器protoc,在Xcode4。  导入位置选择项目根目录.m添加到项目中;autogen,一是直接使用C++版;wiki&#47:  。进入该目录;local&#47,选中”Copy items into destination group‘s folder(if needed)“.2做修改,使最后生成的,最终生成两个文件;usr&#47,就可以直接使用了.1中使用ProtocolBuffer  将步骤2中protobuf-obj&#47:  protoc –objc_out=&#47
资深电脑人
其他类似问题
ios的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁protobuf的安装和使用_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
喜欢此文档的还喜欢
protobuf的安装和使用
p​r​o​t​o​b​u​f..的​源​码​包​,​包​括​怎​样​在​安​装​和​使​用
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢6338人阅读
在移动手机游戏开发中,目前Unity3D已成为比较主流的开发技术。
那么对于客户端服务器协议的打解包,我们有3中常用的处理方式:
1、自定义结构体:在协议中直接传输代码中自定义的结构体;这种方式的坏处是极大的增加了重复性的工作量,并且不能实现协议前后向兼容,可扩展性差;
2、json、xml等文本协议格式: 使用json、xml等文本协议作为协议格式;这种方式的好处是易于开发,方便协议前后向兼容和扩展,缺点是不能序列化,数据量大,浪费带宽;
3、推荐使用的方式: protobuf协议打解包方式;protobuf是google提出的一套开源协议,具有良好的前后向协议兼容性,易于扩展,并且具有很高的序列化和反序列化的效率,能极大的减小传输数据量的大小;
在Unity3D开发中,对于网络部分一般使用C#语言进行开发。一般推荐使用protobuf-net第三方库来进行开发。
但是不幸的是,其中使用到的JIT技术在Unity3D的IOS版本中是不能使用的,在序列化时会导致异常。
经过google网上搜索,找到一种不方便使用的解决方案如下:
但是该方案很复杂,非常不便于操作。
经过笔者自己的实验,探索出下面可用的一种解决方案:
1、从SVN上下载protbuf-net的源码:
http://protobuf-/svn/trunk/protobuf-net
2、将该目录中的所有C#源码拷贝到Unity3D中,直接使用源码而不是第三方dll;
3、此时在Unity中编译时,可能会报错说 unsafe不能使用;
4、采用如下方案可以解决: 在Assets目录下面新建&smcs.rsp文件,并在其中写入 &-unsafe&字符串,前后不加空格;
5、重新启动unity,此时我们可以发现该工程能够通过编译;
经验证,该方案在IOS设备上也是可用的。从而保证我们的protobuf能够应用在Unity移动开发中。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:42032次
排名:千里之外
原创:23篇
转载:22篇
(1)(5)(4)(2)(3)(6)(4)(9)(2)(1)(1)(2)(2)(1)(2)(1)}

我要回帖

更多关于 protobuf net 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信