RPC 框架之 Goole protobuf
Goole 的 protobuf 即 Protocol Buffers 是一個很好的RPC 框架,支持 c++ python java 接下來進行官方文檔的解讀,然後你會對protobuf 會有一個很好的認識:
Protocol buffers are language-neutral, platform-netural extensible mechanism for serializing strutctured data ,think xml . but smaller,faster . and simpler
You define how you want your data to be structured once 。then you can use special generated of soure code to easilly write and read your structured data
to and from a variety of data streams and using a variety of languages
即 protocol buffers 是一個語言中立,平臺中立的 可擴展機制用於序列化結構化的數據,就像xml 一樣,但是它的體積更小,更快,和更簡單(放屁用的,難了誰學),
你需要定義一次你的什麽樣的數據結構,然後即就可以使用特殊生成的源代碼去使用各種語言很輕松的讀和寫你的結構化數據進入到你的各種數據流中
Protocol buffers currently supports generated code in java python ,Objective-C and c++ .With our new proto3 language version ,you can also work with Go ,Ruby ....with more
languages to come
Protocol buffers 當前支持 python .java ob c++ 代碼的生成,在proto3 版本中,支持了GO Ruby 等更多語言;
java 如何使用之官方文檔 tutorials ---指南,教程
the complete sample code for each application is also provided
在官網中每一個應用都提供了完整的例子代碼
this tutorial provides a basic java programmers‘s introduction to working with protocol buffeers ,By walking through creating a simple example application 。it shows you how to
1.Define meassage formats in a .proto file
2.Use the protocol buffer compiler
3.Use the java protocol api to write and read message
這個指南提供了額一個基礎的 java 程序在protobuf 運行介紹,通過建立一個簡單的例子應用,展示你怎麽去
1. 定義消息格式在你的。proto file 文件中
2. 使用protbuf 編譯器
3.使用java api 去讀寫消息
How do you serialize and retrieve structured data like this ? There are a few ways to solve this problem
那你怎麽去序列化和收到結構化數據呢,這是一些方式去解決這些問題
1.use java Seralization this is the default approach since it‘s build into the language ,but it has a host of well-known problems ,and also dosen‘t work very well if you need to
share data with applications written in C++ or python
使用java 序列化,它是默認的方法,因為他是java 的內置的,但是它有很多已知的問題,所以如果你需要去分享數據和其他語言,它不能進行很好的工作就是不能用的意思
RPC 框架之 Goole protobuf