Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Protoc compilation tool

Shulou Source: shulou.com Published: 2022-06-03 04:46:12 11月25日 Update

Before you can develop protoc, you need to install the protoc compilation tool on your computer.

Download the compilation tool

Go to the source code of Protocol Buffers and select the released version to find the corresponding version. The link address for the project is: https://github.com/protocolbuffers/protobuf/releases

Then select https://github.com/protocolbuffers/protobuf/releases/download/v3.9.0/protoc-3.9.0-win64.zip and download the corresponding version.

Please note that if you download version 3.9.0 here, the corresponding version 3.9.0 is also required in the Gradle file of the project.

Please download the corresponding version.

Set environment variabl

After downloading the program, you need to set the bin directory in the download zip file to the environment variable.

Then run protoc-- version to make sure that your compiled run version is configured correctly.

From the following figure, you can view the configured folder.

Determine the correct configuration and compiler version by running protoc-- version.

Convert Java object

Suppose we have a proto file named simple.proto

The code for simple.proto is accessible from the https://github.com/cwiki-us-demo/protocol-buffers-demo-java/blob/master/src/main/proto/simple.proto page.

You can Clone the project locally and execute it.

You can generate a Java object based on the simple.proto file by running the following command

Protoc-proto_path=src-java_out=src/main/java src/main/proto/simple.proto

If the generated results are normal, there should be no output.

Then you can see the generated Java object when you visit a specific folder.

The path and file of the generated file are in the com.insight.demo.protocolbuffers.mode package.

Please note that you cannot compile this file manually, it should be automatically generated by the program.

GitHub sample source code

All the source code in this tutorial is accessible from the https://github.com/cwiki-us-demo/protocol-buffers-demo-java project in GitHub.

You can Clone the code to your local and run the test.

Https://www.cwiki.us/display/ProtocolBuffers/Protoc

Tags: File version compile build run project object source code configuration tool code variable folder environment program selection following figure you can pass command address Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Microsoft Shulou Technology OPPO Reno macOS