Compiling grpc protobuffer files used by the Go version

Source: Internet
Author: User
Tags automake

This article mainly solves the Mac installs the Protobuffer, compiles the go version grpc uses the. Proto file

Installing PROTOC

Note that GRPC need to use Proto3, and the current release version is 2.6.1, so we need to download the source code and compile.

Https://developers.google.com/protocol-buffers/docs/downloads?hl=zh-cn

Protobuf Source in: https://github.com/google/protobuf

Unique pre-installation requirements for Mac

For Mac users, Unix Tools is not available by default, you need to install Xcode first, and then run the following command in Terminal:

$ sudo xcode-select –install

In addition to using DMG, pkg to install software under the Mac, more convenient also useful macports\brew, they can help you install other applications,

Port: https://www.macports.org/install.php

The commands for port installation autoconf Automake Libtool are:

$ sudo /opt/local/bin/port install autoconf automake libtool
Otherwise, we need to compile and install the same as below.
Http://www.cainiaoer.com/2014/10/560.html
Here is a screenshot of my Brew installation:

Compilation of Protocol buffers under Unix

Since our code is GitHub-downloaded, we need to generate the configuration script first

$ ./autogen.sh

This command will download the gtest source to the current directory, and run Automake, autoconf etc to generate the configuration script and makefile of various templates.

If you are using the release package, you can skip this step. Download here, if you are unable to download through the command line, you can manually download, copy to the corresponding directory, but in this sh file comment dropped the line.

Compiling the installation

Execute the following command in turn to complete the compilation and installation.

$ ./configure$ make$ make check$ make install

After the installation is complete, you need to confirm that the installed version is 3. :

For the entire compilation installation process, please refer to:

Https://github.com/google/protobuf

Https://github.com/google/protobuf/blob/master/INSTALL.txt

Install Proto's Go plugin

go get -a github.com/golang/protobuf/protoc-gen-go

-A parameter indication download and do go install directly

Compiling the. Proto file

We are here to compile the proto file as follows, this file name Lm.helloworld.proto, the better habit is to name: PackageName.MessageName.proto:

Syntax = "Proto3";
Package LM;
Message HelloWorld
{
Int32 id = 1; Id
string str = 2; Str
Int32 opt = 3;
}

In PROTOBUF terminology, structured data is referred to as a Message. Proto files are very similar to Java or C-language data definitions.

In this example, the package name is LM, which defines a message helloworld that has three members, the ID of type int32 and opt, and the other is a member of type string str.

Note that we have marked syntax = "Proto3" here;

When the previous proto related tools are ready, we execute the following command to produce the corresponding go implementation class for this IDL file.

Suppose you are executing the command under the directory selected below, expect the production go version of the proto file to be in the LM directory.

Execute the following command.

Protoc-i. /protos. /protos/lm.helloworld.proto--GO_OUT=PLUGINS=GRPC:LM

With the proto file generated in the same directory, the command is:

Protoc-i. /protos. /protos/lm.helloworld.proto--GO_OUT=PLUGINS=GRPC:.

Production of Go code files:

Proto 3 's language guide see: HTTPS://DEVELOPERS.GOOGLE.COM/PROTOCOL-BUFFERS/DOCS/PROTO3?HL=ZH-CN

Compiling grpc protobuffer files used by the Go version

Related Article

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.