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

  1. I think the right way to fix it is to modify the message.h like below
  2. #ifdef __DECCXX
  3. // HP C++'s iosfwd doesn't work.
  4. #include <iostream>
  5. #else
  6. #include <sstream>
  7. //#include <iosfwd>
  8. #endif
  1. Adding #include <istream> to src/google/protobuf/message.cc fixes this problem, as per the latest version of that file in svn.

加入 proto文件自动编译

  1. In Xcode 4.2, open the target properties, go to the "Build Rules" tab and create a new build rule for "*.proto" files
  2. 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_DIR

  3. In Output files, add the generated files (there should be two files, $(INPUT_FILE_BASE).pb.mand $(INPUT_FILE_BASE).pb.h.

  4. 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

  1. -(NSData*)getDataForPacket:(Packet*)packet {
  2. std::string ps = packet->SerializeAsString();return[NSData dataWithBytes:ps.c_str() length:ps.size()];

TO READ FROM NSDATA

  1. -(Packet*)getPacketFromNSData:(NSData*)data {char raw[[data length]];Packet*p =newPacket;[data getBytes:raw length:[data length]];
  2. p->ParseFromArray(raw,[data length]);return p;}

Xcode use Protocol buffer的更多相关文章

  1. cocos2d-x protobuf; cocos2dx protocol buffer

    昨天了解到项目要用到protocol buffer,今天晚上看了一下,了解protobuf本质上就是一个信息表达协议+编辑,解析库. linux开源软件都一个模式,先./configure --hel ...

  2. Protocol Buffer搭建及示例

    本文来源:http://www.tanhao.me/code/150911.html/ Protocol Buffer(简称Protobuf或PB)是由Google推出的一种数据交换格式,与传统的XM ...

  3. 从零开始山寨Caffe·伍:Protocol Buffer简易指南

    你为Class外访问private对象而苦恼嘛?你为设计序列化格式而头疼嘛? ——欢迎体验Google Protocol Buffer 面向对象之封装性 历史遗留问题 面向对象中最矛盾的一个特性,就是 ...

  4. [原创翻译]Protocol Buffer Basics: C#

    Protocol Buffer 基础知识:c#    原文地址:https://developers.google.com/protocol-buffers/docs/csharptutorial   ...

  5. Google Protocol Buffer 的使用和原理[转]

    本文转自: http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/ Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构 ...

  6. Google Protocol Buffer 的使用

    简介 Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,目前已经正在使用的有超过 48,162 种报文格式定义和超过 12,183 ...

  7. 学习Google Protocol buffer之语法

    上一篇结尾的时候问了几个问题,其实主要就是这个protoBuffer协议的语法,弄清楚语法后边才好开展工作嘛,不然大眼而对小眼儿,互相不认识,就没法玩耍了.其实就是学习怎么用google提供的这套 p ...

  8. 学习Google Protocol buffer之概述

    XML这种属于非常强大的一种格式,能存储任何你想存的数据,而且编辑起来还是比较方便的.致命的缺陷在于比较庞大,在某些情况下,序列化和解析都会成为瓶颈.这种对于实时性很强的应用来说,就不太适合了,想象下 ...

  9. Google Protocol Buffer 简单介绍

    以下内容主要整理自官方文档. 为什么使用 Protocol Buffers .proto文件 Protocol Buffers 语法 编译.proto文件 Protocol Buffers API 枚 ...

随机推荐

  1. VMware复制Centos6虚拟机要改的地方

    1.删除文件 /etc/udev/rules.d/70-persistent-net.rules  (它会绑定你网卡信息) 2.重新配置 # vi /etc/sysconfig/network-scr ...

  2. iOS远程消息推送自我整理版

    @interface AppDelegate () <UIApplicationDelegate> @end @implementation AppDelegate - (BOOL)app ...

  3. JavaScript - 测试 jQuery

    测试 JavaScript 框架库 - jQuery 引用 jQuery 如需测试 JavaScript 库,您需要在网页中引用它. 为了引用某个库,请使用 <script> 标签,其 s ...

  4. JavaScript 计时事件

    JavaScript 计时事件 通过使用 JavaScript,我们有能力作到在一个设定的时间间隔之后来执行代码,而不是在函数被调用后立即执行.我们称之为计时事件. 在 JavaScritp 中使用计 ...

  5. C#入门经典(第五版)学习笔记(一)

    ---------------变量和表达式---------------赋值运算符:+=:-=:*=:/=:%=例如:i+=j 相当于 i=i+j i-=j 相当于 i=i-j以此类推 按位运算符:& ...

  6. JavaScript学习笔记之原型对象

    本文是学习<JavaScript高级程序设计>第六章的笔记. JS中,便于批量创建对象的三种模式: 1.工厂模式:用一个函数封装创建对象的细节,传入必要的参数,在函数内部new一个对象并返 ...

  7. Spring配置多数据源错误总结

    由于系统需要调用多个数据源包含mysql,sqlServe和Oracle,所以要在Spring的xml文件中配置多数据源,一下是配置过程中常见的错误: 1.配置的是mysql的数据源,却报oracle ...

  8. cocos2d-x 之 CCArray 源码分析

    cocos2d-x 自己实现了一个数组CCArray ,下面我们来分析一下CCArray的源码 CCArray继承CCObject,所以,CCArray也具有引用计数功能和内存自动管理功能. 数组的源 ...

  9. javascript——面向对象程序设计(1)

    <script type="text/javascript"> //ECMA-262把对象定义为:“无序属性的 集合,其属性可以包含基本值.对象或者函数” //理解对象 ...

  10. HTML5 拖拽 & fabric 插件

    ### 拖拽 //html <div ondrop="drop(event)" ondragover="allowDrop(event)">< ...