Analysis of Google protocol buffers (2)

Source: Internet
Author: User

This article will introduce how to use protocol buffers to complete data serialization and deserialization. the development environment is vs2008, the language is C ++, and the external library uses the googlebuffer library.

1. Google protocol buffer Library

In our applicationsProgramYou need to use the library provided by Google buffer. You can download it from the official website, the author will also provide a simplified lib library for Win32 release (both Debug and x64 versions are deleted, otherwise the Lib package exceeds 200 MB ). : Googlebufferlib

After decompression, we can see that the folder structure is as follows:

--- Googleprotocolbuffer

--- Include folder

--- Lib folder

--- Win32 folder

--- Release folder

--- Proto folder (self-built, put the proto file)

--- Royal folder (self-built. h and. CC directory)

--- *. Lib Library File

---Protoc.exe Compiler

The include folder contains a bunch of header files to be referenced in the program, while the Lib folder contains the protoc compiler and link library.

2. Create and correctly set the project

1) after creating a project using vs2008, copy the googleprotocolbuffer folder downloaded above to your project, as shown in:

2) use the compiler to compile the defined proto file into the. h and. CC files and copy them to the project directory, as shown in:

3) reference the. h and. CC files in the project and add an include "stdafx. H" to the addressbook. Pb. CC header. Otherwise, an error will be reported during compilation.

4) Open project properties, right-click Project-> Configuration-> C/C ++-> General, and set additional include directories as follows:

5) locate configuration-linker-general and set additional library directories as follows:

6) locate configuration-> input-> additional dependencies, as shown in:

7) locate configuration-C/C ++-code generation and change the Runtime Library item to multi-threaded (/mt), as shown in:

The program can be correctly compiled through the attribute settings of some of the above columns, but it does not have any function. next articleArticleWe will introduce how to serialize and deserialize our data.

you are welcome to reprint it. Make sure to keep the original article for reprinting: http://www.cnblo Gs.com/royenhome Thank you for your cooperation!

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.