Cocoaasyncsocket network communication Use PROTOBUF installation (v)

Source: Internet
Author: User
Tags file permissions git clone

Cocoaasyncsocket network communication use PROTOBUF installation (v)

Protocol buffers is Google's tools, mainly used to deal with data serialization and deserialization, to the different types of data compression storage, thereby reducing the size of network data transmission.

In general, when we write data protocol, we need to implement multiple data parsing methods for different platforms, while the other function of protocol buffers is a template customization and multi-platform compilation.

Protocol buffers Native Support C + +, Java, Python, you can use the C + + version of the mixed code on iOS, but the compilation process is cumbersome, we here in iOS using a third-party library (OC version).

Source Address: HTTPS://GITHUB.COM/ALEXEYXO/PROTOBUF-OBJC

Install protocol Buffers

1. Check your Mac for installation homebrew. Using commands: Brew-v

Zhuruhongdemacbook-pro:ios zhuruhong$ brew-v
Homebrew 0.9.5 (git revision 30c54; last commit 2016-02-16)

2. If you have not yet installed, please use the following command to install

Ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"


3. After installing the homebrew, we will install the necessary related tools. Execute the following command sequentially:

Brew Install Automake
Brew install Libtool
Brew Install Protobuf

Note: I have previously installed the PROTOBUF, the middle of the following error. Tell me not linked, the process is as follows:

ZHURUHONGDEMACBOOK-PRO:PROTOBUF-OBJC zhuruhong$ Brew Install Protobuf Already installed, it ' s just not linked ZHURUHONGDEMACBOOK-PRO:PROTOBUF-OBJC zhuruhong$: 
PROTOBUF-OBJC zhuruhong$ Brew link protobuf linking/usr/local/cellar/protobuf/2.6.1 ... Error:could not symlink include/google/protobuf/compiler/code_generator.h target/usr/local/include/google/protobuf /compiler/code_generator.h already exists. You could want to remove it:rm '/usr/local/include/google/protobuf/compiler/code_generator.h ' to force the link and over Write all conflicting files:brew link--overwrite protobuf to list all files that would is deleted:brew link--over Write--dry-run protobuf ZHURUHONGDEMACBOOK-PRO:PROTOBUF-OBJC zhuruhong$ ZHURUHONGDEMACBOOK-PRO:PROTOBUF-OBJC zhuruhong$ Brew link--overwrite protobuf linking/usr/local/cellar/protobuf/2.6.1 ... Symlinks created ZHURUHONGDEMACBOOK-PRO:PROTOBUF-OBJC zhuruhong$ 

Where the brew link--overwrite protobuf command may fail, you should not have permission to overwrite file permissions in the corresponding protocol directory, and then retry the command individually.

4. In order to be able to use the PROTOC command in any directory, we create a shortcut link for Protoc. Of course this is optional, you can configure your own environment variables can also achieve the same effect. Here is the link command:

Ln-s/usr/local/cellar/protobuf/2.6.1/bin/protoc/usr/local/bin


5. Next, we pull the protobuf OC version of the project from Git and store the catalog as it likes. The order is as follows:

git clone https://github.com/alexeyxo/protobuf-objc.git


6. Compile the PROTOBUF-OBJC project just pulled, enter the PROTOBUF-OBJC engineering directory, execute the following order sequentially

./autogen.sh make make
install

Note: If step 3rd installs and links fail, it may not succeed in step 6th. I encountered the following error, after many studies, finally found that the reason is the 3rd step is not linked caused.

./google/protobuf/descriptor.pb.h:2840:50:error:no member named ' Getemptystringalreadyinited ' in namespace ' Google::
                   Protobuf::internal ' if (Package_ = = &::google::p rotobuf::internal::getemptystringalreadyinited ()) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^./google/protobuf/descriptor.pb.h:2848:50:error:no member named ' Getemptystringalreadyinited ' in namespace ' Google::p rotobuf::internal ' if (Package_ = = &::google::p rotobuf:: Internal::getemptystringalreadyinited ()) {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^./google/protobuf/descriptor . Pb.h:2856:50:error:no member named ' Getemptystringalreadyinited ' in namespace ' Google::p rotobuf::internal ' if (packag E_ = = &::google::p rotobuf::internal::getemptystringalreadyinited ()) {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~^./google/protobuf/descriptor.pb.h:2864:50:error:no member named ' Getemptystringalreadyinited ' in namespace ' Google ::p rotobuf::internal ' if (Package_ = = &::google::p rotObuf::internal::getemptystringalreadyinited ()) {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^./google/protobuf/desc Riptor.pb.h:2872:50:error:no member named ' Getemptystringalreadyinited ' in namespace ' Google::p rotobuf::internal ' if ( Package_ = = &::google::p rotobuf::internal::getemptystringalreadyinited ()) {~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~^./google/protobuf/descriptor.pb.h:2876:75:error:no member named ' Getemptystringalreadyinited ' in namespace ' Google::p rotobuf::internal ' Package_ = const_cast<::std::string*> (&::google::p rotobuf::internal::
                                            Getemptystringalreadyinited ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ fatal Error:too Many errors emitted, stopping now [-ferror-limit=] errors generated.

7. Write the. proto file, that is, the data structure of the description file, here not to say, directly test the contents of the file.

Message Person {
    required int32 id = 1;
    Required String name = 2;
    Optional String email = 3;
}

8. Compile the. proto file into Object-c code using the PROTOC command.

Protoc--objc_out=./person.proto    //oc version, we'll just have this protoc--cpp_out=./*.proto//c++            version Proton-java_
out=./*.proto          //java version

9. The use of Protobuf in iOS.

In Podfile, join the OC version of the Protocol Buffers Run-time Library:
pod ' protocolbuffers ', ' ~> 1.9.9.2 '

10. Use the Person object

Introduce PERSON.PB.H,PERSON.PB.M file, compile and run engineering

Demo:https://github.com/zhu410289616/rhsocketkit

Service-Side Engineering Demo:rhsocketserverdemo

Customer Degree Engineering Demo:rhsocketkitdemo

Email:zhu410289616@163.com

qq:410289616

QQ Group: 330585393

2016.2.25

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.