Rust中使用Protocol Buffers

來源:互聯網
上載者:User
關於protobuf

Google Protocol Buffer(簡稱 Protobuf)是一種輕便高效的結構化資料存放區格式,平台無關、語言無關、可擴充,可用於通訊協議和資料存放區等領域。

學習資料: Developer Guide rust中使用protobuf

下面以Ubuntu-16.04LTS為例: 一、安裝protoc 預先安裝

sudo apt-get install autoconf automake libtool curl make g++ unzip
擷取源碼,產生configure
git clone https://github.com/google/protobuf.gitcd protobufgit submodule update --init --recursive./autogen.sh
編譯安裝
./configure  #By default, the package will be installed to /usr/localmakemake checksudo make installsudo ldconfig # refresh shared library cache.

安裝步驟可參考:https://github.com/google/protobuf/blob/master/src/README.md 二、安裝protoc-gen-rust外掛程式

使用cargo 安裝:

cargo install protobuf --vers 1.4.4 #1.4.4為版本號碼,可選填。預設安裝到~/.cargo/bin目錄中

還可使用源碼安裝,從github上clone源碼,編譯安裝,加入環境變數。

安裝步驟可參考:https://github.com/stepancheg/rust-protobuf/tree/master/protobuf-codegen 三、編寫proto檔案產生對應rust檔案

舉例說明(在目前的目錄下產生foo.proto對應的rust檔案):

protoc --rust_out . foo.proto 
四、工程應用 在rust工程中Cargo.toml中的添加protobuf
[dependencies]protobuf = "1.4"
添加引用的crate:
extern crate protobuf;
引用相關api…… 其他 使用情境

 “Protocol Buffers are not designed to handle large messages.”。protobuf對於1M以下的message有很高的效率,但是當message是大於1M的大塊資料時,protobuf的表現不是很好,使用時應當注意。
 

參考文檔:

Protocol Buffers - Google’s data interchange format

rust 使用 protobuf

序列化和還原序列化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.