Install and use Google protocol Buffers

Source: Internet
Author: User
Tags gz file superuser permission

Let's talk about a project similar to Google protocol buffers: thrift from Facebook.

 

 

This article only states the situation in Linux.

(1)first download to the protobuf-2.3.0.tar.gz file.

After the release, you must carefully read readme.txt. The first part of this document describes precautions for installation on UNIX.

The installation process is as follows:

$./Configure
$ Make
$Make check
$ Make install

Note that step 1 has a strange "make check". As the name suggests, it is used for inspection. If "make check" fails, you can still install it, but some functions of Google protocol buffers may not work properly on your system. "Make check" ProcessThe time consumed is relatively long.And wait patiently. In this process, Google test will be called for testing. If you have used Google test, you will know how pleasing the green pass is. The following is the result of "make check" on my RHEL 5:

 

"Make install" may require the superuser permission.

The default installation path is/usr/local. If you want to install it in another path, it is very easy. For example, to install it in/usr, you only need to call configure as follows:

./Configure -- prefix =/usr

 

(2) There are multiple Protocol buffers documents. If you contact them for the first time, you can read several of them in this order: Protocol buffer basics: C ++, language guide, c ++ generated code ,......

 

(3) When compiling a protocol buffers application, use-lprotobuf to link to its dynamic or static library.

 

(4) A friend who just got in touch with protocol buffers may ask, how should protocol buffers be used in the socket communication protocol? You need to compile a. proto file according to your protocol. The format of this file is written according to the requirements of Protocol buffers. Then use the Protocol buffers compiler to generate the class file corresponding to this file (including. h file and one. CC file), and then include the header file generated in your program. When you need to send a socket message, use the serializetostring () method of the object of this class to generate a string, this string is equivalent to the encoded message in the traditional sense. Then, on the receiver of the socket message, use the parsefromstring () method, you can resolve the data contained in the message to the member variables of the generated class, and then use the data directly. The entire process does not require you to consider encoding or decoding. Even if you change the protocol, the modification is very convenient. If you have time, I will write a detailed sample to present it.

 

(To be continued)

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.