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_DIR
In Output files, add the generated files (there should be two files,
$(INPUT_FILE_BASE).pb.m
and$(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 枚 ...
随机推荐
- mysql locktables
SELECT r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, TIMESTAMPDIFF( ...
- reflact中GetMethod方法的使用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- PageMapAdapter MapAdapter (续webServices)
public class PageMapAdapter extends XmlAdapter<PageMapConverter, IPage<Map<String, Object&g ...
- >/dev/null 2>&1 这句话的含义
1表示标准输出,2表示标准错误输出 2>&1表示将标准错误输出重定向到标准输出,这样,程序或者命令的正常输出和错误输出就可以在标准输出输出(也就是一起输出). 一般来讲标准输出和标准错误 ...
- 安装brew
brew brew 又叫Homebrew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件, 只需要一个命令, 非常方便. 安装brew 打开终端窗口, 粘贴以下脚本: ru ...
- PHP 数组转JSON数据(convert array to JSON object);
<?php header('Content-type: appliction/json; charset=shift-JIS'); $data =array(); class Test { pu ...
- C# ToString常用技巧总结
ToString是在开发中最常用的操作,其作用是将其它类型以字符串类型表示.例如: int i=2;i.ToString() //”2″Object o = new Object();o.ToStri ...
- 用css3实现鼠标移进去当前亮其他变灰
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- Code::Blocks 的配色方案
codeblocks的配置文件是default.conf, 在Windows系统下,该文件在C:\Documents and Settings\Administrator\Application Da ...
- tomcat架构分析-索引
出处:http://gearever.iteye.com tomcat架构分析 (概览) tomcat架构分析 (容器类) tomcat架构分析 (valve机制) tomcat架构分析 (valve ...