Protocol Buffers简明教程
随着微服务架构的流行,RPC框架渐渐地成为服务框架的一个重要部分。
在很多RPC的设计中,都采用了高性能的编解码技术,Protocol Buffers就属于其中的佼佼者。
Protocol Buffers是Google开源的一个语言无关、平台无关的通信协议,其小巧、高效和友好的兼容性设计,使其被广泛使用。
概述
protobuf是什么?
Protocol buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured 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 source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
- Google良心企业出厂的;
- 是一种序列化对象框架(或者说是编解码框架),其他功能相似的有Java自带的序列化、Facebook的Thrift和JBoss Marshalling等;
- 通过proto文件定义结构化数据,其他功能相似的比如XML、JSON等;
- 自带代码生成器,支持多种语言;
核心特点
- 语言无关、平台无关
- 简洁
- 高性能
- 良好的兼容性
为什么叫“Protocol Buffers”?
官方如是说:
The name originates from the early days of the format, before we had the protocol buffer compiler to generate classes for us. At the time, there was a class called ProtocolBuffer which actually acted as a buffer for an individual method. Users would add tag/value pairs to this buffer individually by calling methods like AddValue(tag, value). The raw bytes were stored in a buffer which could then be written out once the message had been constructed. Since that time, the “buffers” part of the name has lost its meaning, but it is still the name we use. Today, people usually use the term “protocol message” to refer to a message in an abstract sense, “protocol buffer” to refer to a serialized copy of a message, and “protocol message object” to refer to an in-memory object representing the parsed message.
“变态的”性能表现
有位网友曾经做过各种通用序列化协议技术的对比,我这里直接拿来给大家感受一下:
序列化响应时间对比

序列化bytes对比

具体的数字

快速开始
以下示例源码已上传至github:ginobefun/learning_projects
新建一个maven项目并添加依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.ginobefunny.learning</groupId>
<artifactId>leanring-protobuf</artifactId>
<version>1.0-SNAPSHOT</version> <dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
</project>
转载至:https://zhuanlan.zhihu.com/p/25174418
Protocol Buffers简明教程的更多相关文章
- Protocol Buffers学习教程
最近看公司代码的过程中,看到了很多proto后缀的文件,这是个啥玩意?问了大佬,原来这是Protocol Buffers! 这玩意是干啥的?查完资料才知道,又是谷歌大佬推的开源组件,这玩意完全可以取代 ...
- Protocol Buffers教程
今天想比较下pb和fastjson两个序列化后的大小.再看了一下pb序列化 pb官网:https://developers.google.com/protocol-buffers/ pb是啥 What ...
- Google Protocol Buffers简介
什么是 protocol buffers ? Protocol buffers 是一种灵活.高效的序列化结构数据的自动机制--想想XML,但是它更小,更快,更简单.你只需要把你需要怎样结构化你的数据定 ...
- appium简明教程
appium简明教程 什么是appium? 下面这段介绍来自于appium的官网. Appium is an open-source tool you can use to automate mobi ...
- Google Protocol Buffers介绍
简要介绍和总结protobuf的一些关键点,从我之前做的ppt里摘录而成,希望能节省protobuf初学者的入门时间.这是一个简单的Demo. Protobuf 简介 Protobuf全称Google ...
- Protocol Buffers 在前端项目中的使用
前言: 公司后端使用的是go语言,想尝试用pb和前端进行交互,于是便有了这一次尝试,共计花了一星期时间,网上能查到的文档几乎都看了一遍,但大多都是教在node环境下如何使用,普通的js环境下很多讲述的 ...
- Protocol Buffer学习教程之类库应用(四)
Protocol Buffer学习教程之类库应用(四) 此教程是通过一个简单的示例,给C++开发者介绍一下如何使用protocol buffers编程,主要包括以下几部分: 定义一个.proto文件 ...
- Java网络编程简明教程
Java网络编程简明教程 网络编程 计算机网络相关概念 计算机网络是两台或更多的计算机组成的网络,同一网络内的任意两台计算机可以直接通信,所有计算机必须遵循同一种网络协议. 互联网 互联网是连接计算 ...
- ProtoBuf3语法指南(Protocol Buffers)_下
0.说明 ProtoBuf3语法指南, 又称为proto3, 是谷歌的Protocol Buffers第3个版本. 本文基于官方英文版本翻译, 加上了自己的理解少量修改, 一共分为上下两部分. 1.A ...
随机推荐
- java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 不能使用 '(未知的)';文件已在使用中
最近查看程序输入的日志时发现一个java连接Access的程序时不时的抛出: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driv ...
- 二分图判定 POJ-2492
这是由AC代码改的模板,不能直接交啊 #include<iostream> #include<vector> #include<cstring> using nam ...
- maveb安装与配置(win10)
转载:https://www.cnblogs.com/eagle6688/p/7838224.html 看了几篇博客,感觉这篇博客写的含金量最高了,因为我电脑的系统是win10的,所以配置有细微的差别 ...
- linux_shell使用
一.hash命令 说明:linux系统下会有一个hash表,当你刚开机时这个hash表为空,每当你执行过一条命令时,hash表会记录下这条命令的路径,就相当于缓存一样.第一次执行命令shell解释器默 ...
- 利用U盘启动制作GHO镜像
利用U盘启动制作GHO镜像 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. In a realproduction environment. 我们我们可能遇到频繁的安装系统,安装环境 ...
- Linux记录-Linux Swap分区虚拟内存相关解决方案
Swap用途:Swap意思是交换分区,通常我们说的虚拟内存,是从硬盘中划分出的一个分区.当物理内存不够用的时候,内核就会释放缓存区(buffers/cache)里一些长时间不用的程序,然后将这些程序临 ...
- GC.SuppressFinalize()的正确用法
SuppressFinalize函数是: 该方法在对象头中设置一个位,系统在调用终结器时将检查这个位.obj 参数应为此方法的调用方. 实现 IDisposable 接口的对象可以从 IDisposa ...
- spring注解第07课 @Valid和@Validated的总结区分
@Valid: @Valid注解用于校验,所属包为:javax.validation.Valid. ① 首先需要在实体类的相应字段上添加用于充当校验条件的注解,如:@Min,如下代码(age属于Gir ...
- 七、UART
7.1 介绍 UART(Universal Asynchronous Receiver Transmitter),通用异步收发器,用来传输穿行数据时 UART 之间以全双工方式传输数据,连线方法只有 ...
- nmap扫描出现tcpwrapped
FAQ tcpwrapped From SecWiki Jump to: navigation, search What does "tcpwrapped" mean? tcpwr ...