Xcode use Protocol buffer
http://stackoverflow.com/questions/10277576/google-protocol-buffers-on-ios
http://stackoverflow.com/questions/8759202/google-protocol-buffers-on-ios-objective-c
#### build 2.4.1 failed on mac os x 10.9
I think the right way to fix it is to modify the message.h like below
#ifdef __DECCXX
// HP C++'s iosfwd doesn't work.
#include <iostream>
#else
#include <sstream>
//#include <iosfwd>
#endif
Adding #include <istream> to src/google/protobuf/message.cc fixes this problem, as per the latest version of that file in svn.
加入 proto文件自动编译
- In Xcode 4.2, open the target properties, go to the "Build Rules" tab and create a new build rule for "*.proto" files
In "Using:", choose "custom script" and use a script like this:
protoc --plugin=/usr/local/bin/protoc-gen-objc $INPUT_FILE_PATH --objc_out=$DERIVED_FILES_DIRIn Output files, add the generated files (there should be two files,
$(INPUT_FILE_BASE).pb.mand$(INPUT_FILE_BASE).pb.h.- Add the .proto files to your project.
To compile and test the easiest way Ive found is to just import the whole google directory in my own project :) (the second time you can make your own framework but for testing this procedure just works)
- download latest version
- autogen configure and make like you were just building for macosx (you need command line tools) . This way you end up with protoc
binary and the library for macosx (which you don't need) - open your Xcode iOS project
- add "new file" to your project and select google directory
- add the directory of google headers to your additional include directories
- add config.h from the protobuffer src directory to your app
- from the google group remove everything that contains unitest :)
- from the google group remove compiler and java stuff;
You should be able to compile without any linking error. To give you an idea this is what I directly compile

Then you can use protoc to generate c++ source files for your protocol. To use them with objc you have to rename your source to file "mm" then you can do something like
TO SERIALIZE TO NSDATA
let's say your message is called Packet
-(NSData*)getDataForPacket:(Packet*)packet {
std::string ps = packet->SerializeAsString();return[NSData dataWithBytes:ps.c_str() length:ps.size()];
TO READ FROM NSDATA
-(Packet*)getPacketFromNSData:(NSData*)data {char raw[[data length]];Packet*p =newPacket;[data getBytes:raw length:[data length]];
p->ParseFromArray(raw,[data length]);return p;}
Xcode use Protocol buffer的更多相关文章
- cocos2d-x protobuf; cocos2dx protocol buffer
昨天了解到项目要用到protocol buffer,今天晚上看了一下,了解protobuf本质上就是一个信息表达协议+编辑,解析库. linux开源软件都一个模式,先./configure --hel ...
- Protocol Buffer搭建及示例
本文来源:http://www.tanhao.me/code/150911.html/ Protocol Buffer(简称Protobuf或PB)是由Google推出的一种数据交换格式,与传统的XM ...
- 从零开始山寨Caffe·伍:Protocol Buffer简易指南
你为Class外访问private对象而苦恼嘛?你为设计序列化格式而头疼嘛? ——欢迎体验Google Protocol Buffer 面向对象之封装性 历史遗留问题 面向对象中最矛盾的一个特性,就是 ...
- [原创翻译]Protocol Buffer Basics: C#
Protocol Buffer 基础知识:c# 原文地址:https://developers.google.com/protocol-buffers/docs/csharptutorial ...
- Google Protocol Buffer 的使用和原理[转]
本文转自: http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/ Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构 ...
- Google Protocol Buffer 的使用
简介 Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,目前已经正在使用的有超过 48,162 种报文格式定义和超过 12,183 ...
- 学习Google Protocol buffer之语法
上一篇结尾的时候问了几个问题,其实主要就是这个protoBuffer协议的语法,弄清楚语法后边才好开展工作嘛,不然大眼而对小眼儿,互相不认识,就没法玩耍了.其实就是学习怎么用google提供的这套 p ...
- 学习Google Protocol buffer之概述
XML这种属于非常强大的一种格式,能存储任何你想存的数据,而且编辑起来还是比较方便的.致命的缺陷在于比较庞大,在某些情况下,序列化和解析都会成为瓶颈.这种对于实时性很强的应用来说,就不太适合了,想象下 ...
- Google Protocol Buffer 简单介绍
以下内容主要整理自官方文档. 为什么使用 Protocol Buffers .proto文件 Protocol Buffers 语法 编译.proto文件 Protocol Buffers API 枚 ...
随机推荐
- Gprinter Android SDK V2.1.4 使用说明
佳博打印机Android的SDK开发包,已更新到Gprinter Android SDK V2.1.4. IOS的SDK开发包更新为GprinterSDKandDemoforIOS_v1.0.8. 根 ...
- iOS 从网络获取son并解析
NSString* GXURL = PURL; GXURL = [GXURL stringByAppendingString:@"/index.php/Api/android_getRank ...
- Objective-C中的分类与协议
分类 在谈分类之前,我们可以先探究下,OC中为什么出现分类这种机制,有什么好处? 假设你接到一个大项目:计算两个整数的和,差.接到任务的你马上动手.编写代码如下: #import <Founda ...
- MySQL的C++简单封装
/* *介绍:MySQL的简单封装,支持流操作输入输出MySQL语句,然而并没有什么软用,大二学生自娱自乐,有不足求指点 *作者:MrEO *日期:2016.3.26 */ 头文件 my_sql.h ...
- 24种设计模式--工厂方法模式【Factory Method Pattern】
女娲补天的故事大家都听说过吧,今天不说这个,说女娲创造人的故事,可不是“造人”的工作,这个词被现代人滥用了. 这个故事是说,女娲在补了天后,下到凡间一看,哇塞,风景太优美了,天空是湛蓝的,水是清澈的, ...
- 关于this
一:全局环境中的this指的是window对象 二:作为对象的方法调用 当函数作为对象的方法被调用时,this指向该对象 例子: 三:作为普通方法调用 当函数不作为对象的属性被调用,而是作为普通函数函 ...
- Win8.1 64bit安装Genymotion模拟器
其实安装并不复杂,只要环境正常,此事并不难.但估计最坏的情况都被我撞上了,才折腾了差不多一天的 那我有哪些环境不正常呢? 破解了系统主题 Device Install Service服务未启动 下面来 ...
- Python,遍历目录下TXT
import os #获取根目录,递归得到所以txt文件的路径 list_dirs = os.walk(os.curdir) txtfilenames=[] for root, dirs, files ...
- spart快速大数据分析学习提纲(一)
Spart是什么 Spart是一个用来实现快速而而通用的集群计算平台. 在速度方面,Spart扩展了广泛使用的Mapreduce计算模型,而且高效的支持更多的计算模式,包括交互式查询和流处理.Spar ...
- phalapi
public为程序入口 Demo和MyApp为具体的实现 public为多入口 demo和myapp都是入口,但是进入后即又为单入口 list为接口文档,是自动解析程序里的注释自动生成的文档 框架执行 ...