Protocol Buffers for IOS

7,271 views
Skip to first unread message

Dhanaraj G

unread,
Mar 31, 2012, 4:31:07 AM3/31/12
to Protocol Buffers
Hi,

Is there any direct support for Protocol Buffers in iOS? (armv6,
armv7)

I have gone through he following link..
http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers

It uses v2.2 and currently available version is v2.4


Regards,
Dhanaraj

Evan Jones

unread,
Mar 31, 2012, 7:50:00 PM3/31/12
to Dhanaraj G, Protocol Buffers
On Mar 31, 2012, at 4:31 , Dhanaraj G wrote:
> I have gone through he following link..
> http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers


There is no "official" support but I've used the following distribution with success, with the latest protoc (I'm pretty sure):

https://github.com/booyah/protobuf-objc


Good luck,

Evan

--
http://evanjones.ca/

Dhanaraj G

unread,
Apr 2, 2012, 8:04:21 AM4/2/12
to Protocol Buffers
One more option i found is in following link..

http://tinsuke.wordpress.com/2011/02/17/how-to-cross-compiling-libraries-for-ios-armv6armv7i386/


We just need to copy the following file to /protobuf-2.4.1/ folder

http://goo.gl/OuP7f

then give the command in terminal

cd protobuf-2.4.1/
bash build_dependencies.sh

You will get the universal binary in protobuf-2.4.1/outdir folder

Regards,
Dhanaraj

Nicola Ferruzzi

unread,
Apr 2, 2012, 8:34:26 PM4/2/12
to Protocol Buffers

> Is there any direct support for Protocol Buffers  in iOS? (armv6,
> armv7)
>
> I have gone through he following link..http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers
>
> It uses v2.2 and currently available version is v2.4

I use latest version in my app .. you don't really need objc direct
support if you are familiar with C++, there is only one point where
you have to pass from std::string to NSData and viceversa. And its
pretty simple.

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
http://dl.dropbox.com/u/29537941/Screen%20Shot%202012-04-03%20at%2002.22.06.png

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 = new Packet;
[data getBytes:raw length:[data length]];
p->ParseFromArray(raw, [data length]);
return p;
}

this should give you a good start :)
-Nicola

Nicola Ferruzzi

unread,
Sep 12, 2012, 3:57:23 PM9/12/12
to Sebastian Suchanowski, prot...@googlegroups.com
Hi,

Ive added a new screenshot at this url, I hope it can help


in my .mm file I just include my generated protocol.h 
and in my "Header Search Paths" Ive the full path to my proto src (ie .../protobuf-2.4.1/src)

So far Ive been using it for months with no problems

-Nicola


On Tue, Sep 11, 2012 at 11:50 AM, Sebastian Suchanowski <s.such...@gmail.com> wrote:
Hey,

Doing every steps I've problem with #include notation. What I mean is I get

'google/protobuf/stubs/common.h' file not found

at this line

#include <google/protobuf/stubs/common.h>


and if I change it to 


#include "common.h"


Then everything is ok, but this is stupid way to do and there is like gazylion files :P

How you manage to deal with it? You dropbox link doesn't work - could you correct it, maybe it may help.


Thanks.

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/XM9qZIqixQ0J.

To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.

Reply all
Reply to author
Forward
0 new messages