Use protocol buffers in rust

Source: Internet
Author: User
Tags git clone
About PROTOBUF

Google Protocol Buffer (abbreviated PROTOBUF) is a lightweight and efficient structured data storage format, platform-Independent, language-independent, extensible, and can be used in communication protocols and data storage and other fields.

Learning materials: Developer Guide rust used in protobuf

The following take Ubuntu-16.04lts as an example: first, install PROTOC pre-installed

sudo apt-get install autoconf automake libtool Curl make g++ Unzip
Get source code, generate configure
git clone https://github.com/google/protobuf.git
cd protobuf
git submodule update--init--recursive
./ autogen.sh
Compiling the installation
./configure  #By Default, the package is installed to/usr/local make
to
check
sudo make Install
  sudo Ldconfig # Refresh shared library cache.

Installation steps can refer to: https://github.com/google/protobuf/blob/master/src/README.md Two, install Protoc-gen-rust plug-in

Using Cargo Installation:

Cargo install Protobuf--vers 1.4.4 #1.4.4 is a version number, optionally filled. Install by default to the ~/.cargo/bin directory

can also use the source code installation, from the GitHub clone source code, compile installation, add environment variables.

Installation steps can refer to: Https://github.com/stepancheg/rust-protobuf/tree/master/protobuf-codegen three, write proto file generation corresponding rust file

For illustration (generate Foo.proto corresponding rust file in current directory):

Four, the application of engineering in the Rust Project Cargo.toml added Protobuf
[Dependencies]
Protobuf = "1.4"
To add a reference to the crate:
extern crate Protobuf;
Referencing related APIs ... Other usage Scenarios

"Protocol buffers are not designed to handle large.". Protobuf is highly efficient for message below 1M, but when message is larger than 1M data, protobuf performance is not very good, should be noted when used.
 

Reference Documentation:

Protocol Buffers-google ' s Data Interchange Format

Rust Use Protobuf

Serialization and deserialization

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.