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
1.使用java 序列化,它是默认的方法,因为他是java 的内置的,但是它有很多已知的问题,所以如果你需要去分享数据和其他语言,它不能进行很好的工作就是不能用的意思
2.you can invent an ad-hoc way to encode the data items into a singal string 。such as encoding 4 ints as "12:3:-23:67" this is a simple and flexible approach although
it dose require writing one-off encoding and parsing code and the parsing imposes a small run-time cost . this works best for enoding very small data
2.你可以发明一种 ad-hoc 的 方式去编码数据条目成为字符串 ,比如 编码4个整数 为12:3:-23;67 这是一个简单而且灵活的方式,虽然他需要编写一次性的编码和解析代码
以及 解析代码会强加一些运行时的损耗 ,所以如果编码小的数据的话,他可以很好的工作
3.Serialize the data to XML ,this approach can be very attractive since XML is (sort of) human readable and there are binding libraries for lots of languages .this can be a good choice if you want to share date with other appliation/project . however XML is notoriously space intensive and encoding/decoding it can impose a huge performance penalty
on application also navigating an xml DOM tree is considerably more complicated than navigating simple fields in class normally would be
3.序列化data 成xml ,这个方法是非常有吸引力的,因为XML 是一个人类可读的和 在很多语言中都有关于XMl的绑定库 如果你想要和其他语言应用进行分享数据,这是一个很好的选择,然而 xml 是臭名昭著的占据空间 ,在应用中,它编解码会强加很多性能执行的坏处损耗,xml dom 树导航 是非常的复杂的比去遍历class字段
-----显然,上面3点都有自己的局限性,看protocolbuffers 给我们提供了什么?
Protocol buffers are flexible ,efficient automated solution to solve exactly this problem, With Protocol buffers ,you writer a .proto description of data structure you wish to store
From that. protocol compiler creates a class that implemients automatic encoding and parsing of the protocol buffer data with an efficient binary format The generated class provides getter and setters as aunit ,importantly .the protocolbuf format supports the ideas of extending the format over time in such a way that the code can still read data
encoded with the old format
protocol buffers 是一个灵活的 有效的自动化解决方案去正确的解决这个问题(上面的三点),对于Protocol buffers 你可以写一个你希望存储的结构化描述proto 文件
针对这个文件,protocol 编译器会生成一个class文件 自动实现了在有效的的二进制protocol buffer 数据格式中进行编码与解码 生成的class 提供了get set 方法
重要的是 protocolbuf 格式支持一个思想就是 这个格式随着时间的推移,这些code 仍然可以读取数据,用旧的格式编码
------接下来就是 .pro文件改如何编写,官网有很好的例子:
The proto file starts with a package declaration .which helps to prevent naming conflicts between different project 。the package name is used as the java package unless you
have explicitly specified a java_package . as we have here even if you do provide a java_package .you should still define a normal package as well to avoid name collisions
in the protocol buffers name space as well as in no java languages
proto 文件以一个包名声明开始,它是用来去阻止在不同的工程中的命名冲突,这个包名被用作java 的包 除非你已经明确指定了一个 java_package,但是呢, 尽管你已经提供了一个java_package,你也应该仍然定义一个 正常的包名来避免在protobuf 命名空间中的命名冲突 在不是java 环境下的
说白了,我们开发中,必须定义package 与 java_package ,包名以java_package 为准
The =1,=2 markers on each element identify the unique 'tag' that field uses in the binary encoding . tag-numbers 1-15 require one less byte to encode than height number
RPC 框架之 Goole protobuf的更多相关文章
- rpc框架: thrift/avro/protobuf 之maven插件生成java类
thrift.avro.probobuf 这几个rpc框架的基本思想都差不多,先定义IDL文件,然后由各自的编译器(或maven插件)生成目标语言的源代码,但是,根据idl生成源代码这件事,如果每次都 ...
- RPC框架实现(一) Protobuf的rpc实现
概述 RPC框架是云端服务基础框架之一,负责云端服务模块之间的项目调用,类似于本地的函数调用一样方便.常见的RPC框架配带的功能有: 编解码协议.比如protobuf.thrift等等. 服务发现.指 ...
- rpc框架之gRPC 学习 - hello world
grpc是google在github于2015年开源的一款RPC框架,虽然protobuf很早google就开源了,但是google一直没推出正式的开源框架,导致github上基于protobuf的r ...
- 谷歌发布的首款基于HTTP/2和protobuf的RPC框架:GRPC
Google 刚刚开源了grpc, 一个基于HTTP2 和 Protobuf 的高性能.开源.通用的RPC框架.Protobuf 本身虽然提供了RPC 的定义语法,但是一直以来,Google 只开 ...
- gRPC:Google开源的基于HTTP/2和ProtoBuf的通用RPC框架
gRPC:Google开源的基于HTTP/2和ProtoBuf的通用RPC框架 gRPC:Google开源的基于HTTP/2和ProtoBuf的通用RPC框架 Google Guava官方教程(中文版 ...
- 基于HTTP/2和protobuf的RPC框架:GRPC
谷歌发布的首款基于HTTP/2和protobuf的RPC框架:GRPC Google 刚刚开源了grpc, 一个基于HTTP2 和 Protobuf 的高性能.开源.通用的RPC框架.Protobu ...
- 基于Protobuf的分布式高性能RPC框架——Navi-Pbrpc
基于Protobuf的分布式高性能RPC框架——Navi-Pbrpc 二月 8, 2016 1 简介 Navi-pbrpc框架是一个高性能的远程调用RPC框架,使用netty4技术提供非阻塞.异步.全 ...
- 全图文分析:如何利用Google的protobuf,来思考、设计、实现自己的RPC框架
目录 一.前言 二.RPC 基础概念 1. RPC 是什么? 2. 需要解决什么问题? 3. 有哪些开源实现? 三.protobuf 基本使用 1. 基本知识 2. 使用步骤 四.libevent 1 ...
- RPC框架性能基本比较测试
RPC框架:gRPC.Thrift.Wildfly.Dubbo 原文链接:http://www.open-open.com/lib/view/open1426302068107.html gRPC是G ...
随机推荐
- jquery 设计的思路-----初级
jquery.js 很经典,其中有一些设计思路简直非常经典 1.安全的创建一个构造函数并进行调用: <script> // 这是一种安全的构造函数的创建方法,在调用构造函数G的时候,不论使 ...
- vue:图片切换动态显示
<img :src="切换条件 ? require('xxx.png') : require('xxx.png')" />
- leetcode AC1 感受
在网上第一个AC还是蛮高兴的,之前试了不少练习编程的方法,感觉不怎么适合自己,在OJ上做题的确是一个能够锻炼的方法. 之前一直研究学习的方法,往简单的说是认知.练习,往复杂的说是,保持足够input, ...
- 在postgresqlz中查看与删除索引
查看索引 select * from pg_indexes where tablename='tbname'; 或者 select * from pg_statio_all_inde ...
- 转: jquery.qrcode.js生成二维码插件&转成图片格式
原文地址: https://blog.csdn.net/u011127019/article/details/51226104 1.qrcode其实是通过使用jQuery实现图形渲染,画图,支持can ...
- Oracle数据文件迁移到裸设备
本文主要描述如何将Oracle表空间的文件系统形式的数据文件迁移到LV裸设备上. 前提条件 1.oracle运行正常. 2.已使用LVM命令规划好LV文件.如/dev/vgoracle/lvdatat ...
- [ SHELL编程 ] echo和printf使用实例
本文主要描述Linux系统中echo和printf命令的使用方法,包括命令参数的含义.使用技巧. 1.echo 了解一个命令我们首先要知道它能做什么,它有哪些参数,参数的含义,可以实现我们哪方面 ...
- mysql 5.7.3.0-m13安装教程
安装mysql百度经验地址:(默认安装,除了选择不更新和选择保存路径,其它基本是下一步下一步) http://jingyan.baidu.com/article/7e440953d6f0702fc1e ...
- JS-cookie和正则表达式
一 cookie 1 什么是cookie? 会话跟踪技术 2 作用 验证身份,存储信息. 3 特点 大小限制,最多存4k: 每个域下只能存50个cookie: 有时间限制: 只能存放字符串: 只能访问 ...
- rem是如何实现自适应布局的
原文链接:http://caibaojian.com/web-app-rem.html 摘要:rem是相对于根元素<html>,这样就意味着,我们只需要在根元素确定一个px字号,则可以来算 ...