Google protocol buffer Use notes __google

Source: Internet
Author: User
A moment to download
Google Download Address: Https://developers.google.com/protocol-buffers/docs/downloads?hl=zh-CN
GitHub Download Address: https://github.com/google/protobuf
I download version here: protobuf-2.6.1.tar.gz


Second compilation
1 decompression
Extract the above compressed package into the folder protobuf-2.6.1.


2 compiling
2.1 In protobuf-2.6.1, find Vsprojects/protobuf.sln, double-click with vs to open.
2.2 Set the compile mode to release mode, then compile Libprotobuf,libprotobuf-lite,libprotoc,protoc (right key-> build).


3 Copy Library
In Vsprojects\release find Libprotobuf.lib,libprotobuf-lite.lib,libprotoc.lib and Protoc.exe, copy to C:\Windows directory.


4 Generating header files
Double-click Extract_includes.bat to generate an include directory under the Vsprojects directory.


Three compiler Proto
1 Create a new Person.proto in the D:/GPB directory and edit the contents as follows:
Package proto;


Message person {
  Required String name = 1;
  Required Int32 id = 2;
  Optional String email = 3;
}
#gpb即Google Protocol Buffer


2 generating C + + classes
In the GPB file, right-click-> to open the command line here, enter:
Protoc.exe Person.proto--cpp_out=.


This generates the person class under the current folder, and the file is as follows:



Four Proto detailed explanation
1 Key Words
The package keyword is to specify a namespace
Message keyword, similar to struct in C or class in C + + and Java


2 Property Description
Required non-empty fields
Optional optional fields
A field represented by repeated can contain 0 or more data.


3 types

As shown in figure:



Original link: http://blog.csdn.net/xufeng0991/article/details/45031211

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.