Giter VIP home page Giter VIP logo

protobuf-ios's Introduction

protobuf-ios

Introduction

travis-ci build status

An Objective-C implementation of Google proto buffer for iOS. The orignal code comes from Booyah Inc. This implemenation add features to support write to / parse from delimited stream. This git repo also support cocoapods.

Supported Platform

  • iOS 4.0 and above
  • Xcode 4 and above

Features

  • Support write to / parse from delimited stream (protobuf 2.3 feature).

Examples

Simple Usage

You write a foo.proto file like this:

message Person {
    required int32 id = 1;
    required string name = 2;
    optional string email = 3;
}

Then you compile it with protoc to produce code in Objective-C (see below).

Serialize to protobuf format:

Person* person = [[[[[Person builder] setId:123]
                                    setName:@"Bob"]
                                   setEmail:@"[email protected]"] build];
NSData* data = [person data];

Unserialize from protobuf format data:

NSData* raw_data = ...;
Person* person = [Person parseFromData:raw_data];

Delimited encode

Sometime is very useful to write multiple protobuf objects into a single file. This need use delimited format. Here is an example:

// serialize
NSOutputStream *ouputStream = [NSOutputStream outputStreamToFileAtPath:@"filename.dat" append:YES];
[ouputStream open];
for (int i=0; i<count; i++) {
    // create a new Person object and assign value.
    Person* person = ...;
    
    // write to stream use delimited format
    [person writeDelimitedToOutputStream:outputStream];
}

// unserialize
NSInputStream* inputStream = ...;
while(true) {
    // read object one by one from stream.
    Person* person = [Person parseDelimitedFromInputStream:inputStream];
    if (!person) {
        break;
    }
    
    ....
    ....
}

Xcode integration

Integrate with CocoaPods

If your project support cocoapods, add a line to your Podfile:

pod 'protobuf-ios'

Then update your dependences:

pod update

Integrate with source code

Drag protoc-ios.xcodeproj to your Xcode project.

That's all.

Compiler setting

Since the generated code is non-ARC, if your project use ARC by default, you need add -fno-objc-arc to generated files.

In Xcode, select the main project/targets/build phases/compile sources, select the m files/double click under compiler flag/add -fno-objc-arc to the popped window.

How to use

Get the compiler

Run following command to compile and install the project.

$ cd compiler
$ ./autogen.sh
$ ./configure
$ make
$ make install (optional)

The compiler is genrated at src/protoc.

Note:

You need autoconf to compile from source code. If your system is not install autoconf, you can install it by brew:

$ brew install autoconf

If you system already install autoconf but linked, you can link it, here is an example:

$ brew install autoconf
Warning: autoconf-2.69 already installed, it's just not linked    
$ brew link autoconf
Linking /usr/local/Cellar/autoconf/2.69... 28 symlinks created

Usage

To compile the proto definition to Objective-C, use following command:

./src/protoc --objc_out=. foo.proto

Contribution

Contributions are welcome!

If you would like to contribute this project, please feel free to fork and send pull request.

Credits

References

protobuf-ios's People

Contributors

mingchen avatar readmecritic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

protobuf-ios's Issues

problem with ./autogen.sh and ./configure

hi!
i'm trying to follow installation instructions:
cd compiler
./autogen.sh
./configure
make
make install (optional)

and got this:
192-168-1-163:compiler alextsyss$ ./autogen.sh
sed -i -e 's/RuntimeLibrary="5"/RuntimeLibrary="3"/g;
s/RuntimeLibrary="4"/RuntimeLibrary="2"/g;' gtest/msvc/gtest.vcproj gtest/msvc/gtest_color_test_.vcproj gtest/msvc/gtest_env_var_test_.vcproj gtest/msvc/gtest_environment_test.vcproj gtest/msvc/gtest_main.vcproj gtest/msvc/gtest_output_test_.vcproj gtest/msvc/gtest_prod_test.vcproj gtest/msvc/gtest_uninitialized_test_.vcproj gtest/msvc/gtest_unittest.vcproj
autoreconf -f -i -Wall,no-obsolete

./autogen.sh: line 28: autoreconf: command not found

192-168-1-163:compiler alextsyss$ ./configure
-bash: ./configure: No such file or directory

192-168-1-163:compiler alextsyss$ make
make: *** No rule to make target m4/libtool.m4', needed byMakefile.in'. Stop.

192-168-1-163:compiler alextsyss$ make install
make: *** No rule to make target m4/libtool.m4', needed byMakefile.in'. Stop.

192-168-1-163:compiler alextsyss$

what am I doing wrong?

Built test program, does not compile

I built a dummy app to test this and simply included the *.pb.h *.pb.m files by dragging from finder and selecting copy if necessary.

I did the same with protobuf-ios.xcodeproj and tried to build it.

I get an error on

import "ProtocolBuffers.h"

in the .pb.h file

It seems that the files which appear to be included are not actually usable.

update :- when you include the xcodeproj in your target project you may get an error that this project does not support the required architecture. Under "build settings" you need to change to Standard Architectures.

请问如何在swift中使用

你好。请问你有在swift项目中使用protobuf么。我在swift中使用遇到一些问题。想请教你,方便留个qq吗?

Warnings Removal

Hey! Thanks for sharing this project!

There are a couple of warnings in CodedOutputStream.h,
Multiple declarations of methods writeRawLittleEndian32: and writeRawLittleEndian64:
Could that be rectified whenever you update the code next?

Static Library

Hi.

Can you please configure project to generate Static Library of protobuf-ios ?

i want to use your fork in my game.

Thank you.

XCode 5 - make fails

Hi,

while attempting to build the compiler on Mavericks 10.9.3 and XCode 5.1 this error raises on "make"

google/protobuf/message.cc:135:67: error: implicit instantiation of undefined template
'std::__1::basic_istream<char, std::__1::char_traits >'
return ParsePartialFromZeroCopyStream(&zero_copy_input) && input->eof();
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iosfwd:109:33: note:
template is declared here
class _LIBCPP_TYPE_VIS_ONLY basic_istream;

Any fix for this?

RpcServices support?

Having services.proto file:

syntax = "proto2";

option java_generic_services = true;
option java_package = "com.company.api.proto";

import "wifi.proto"; 

service InstallService {
    rpc getWifiNetworks (WifiRequest) returns (WifiResponse);
}

I can generate RpcService files for java, but not for obj-c:

MBA-Anton:proto asmirnov$ /softdev/protobuf-ios/compiler/src/protoc --objc_out=./obj-c/ ./service.proto 
service.proto:3:8: Option "java_generic_services" unknown.

Any similar options for objective-c? Rpc supported?

Message can't be build to NSData.

Hi, Chen Ming
Thanks for share this project. I have some problems with this version.
In my project, i can use the automake cmd to generate the protoc tool.
And i can use the protoc to generate the .pb.m and .pb.h. But, i can't use the function to generate the NSData.

Here is my code:

UpStream_Builder *up = [[UpStream_Builder alloc] init];
[up setUid:@"18566759117"];
[up setUType:0];
[up setPassword:@"123456"];
[up setSeq:567];
[up setVersion:@"100"];
[up setData:nil];
[up setExtra:nil];
[up setDeviceInfo:@"iphone"];
[up setCmd:@"register"];

NSData *upData = [[up build] data];

the upData is nil.

Do you and your users meet that problems?

PS. when i execute the ./autogen.sh, There some error of subdir-objects error, So, i google it and change the ./configure.ac which "AM_INIT_AUTOMAKE" to "AM_INIT_AUTOMAKE(subdir-objects)". And warning that there some lib not in POSIX format. i don't know that is wrong or correct.
I have upload the pictures, thanks!
Uploading 2.JPG . . .
Uploading endMakeCMD.JPG . . .
Uploading 3.JPG . . .

[Solved] A lot of errors

After I add your library to Xcode via cocoa pods, a lot of error immediately happens:
1, Can not find explicit declaration of interface NSObject;
after some search around, this one can be solved by via adding "import "UIKit/UIKit.h" to the .h file generated by photobuf compiler;

2, Your library is NOT built for automatic reference counting!!!
Sorry, this issue can be solved by adding compile flag "-fno-objc-arc" to *.m files generated by the protobuf compiler. In Xcode, select the main project/targets/build phases/compile sources/select the m files/double click under compiler flag/add "-fno-objc-arc" to the popped window.

Update to 2.6.1?

I've found protoc uses 2.2 sources which are pretty old. Any chance to get update for 2.6.1? Is it full compatible with 2.6.1? What about 3.0.0?

Class Prefix support?

seems not support class prefix,

with this line option (.google.protobuf.objectivec_file_options).class_prefix = "LL";

protoc produces error Option "(.google.protobuf.objectivec_file_options)" unknown.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.