Protobuf

来自软件开发
Wzwyc讨论 | 贡献2019年9月26日 (四) 07:46的版本 (创建页面,内容为“=== Protobuf是什么 === Protobuf实际是一套类似Json或者XML的数据传输格式和规范,用于不同应用或进程之间进行通信时使用。通信…”)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

Protobuf是什么

Protobuf实际是一套类似Json或者XML的数据传输格式和规范,用于不同应用或进程之间进行通信时使用。通信时所传递的信息是通过Protobuf定义的message数据结构进行打包,然后编译成二进制的码流再进行传输或者存储。


Protobuf的优点

相比较而言,Protobuf有如下优点:

  • 足够简单
  • 序列化后体积很小:消息大小只需要XML的1/10 ~ 1/3
  • 解析速度快:解析速度比XML快20 ~ 100倍
  • 多语言支持
  • 更好的兼容性,Protobuf设计的一个原则就是要能够很好的支持向下或向上兼容

protobuf-net

Protobuf的早期版本不支持C#?可以借助protobuf-net

protobuf-net is a contract based serializer for .NET code, that happens to write data in the "protocol buffers" serialization format engineered by Google. The API, however, is very different to Google's, and follows typical .NET patterns (it is broadly comparable, in usage, to XmlSerializer, DataContractSerializer, etc). It should work for most .NET languages that write standard types and can use attributes.

github地址:https://github.com/mgravell/protobuf-net

Install-Package protobuf-net

ProtoGen

CLI tool to parse protobuf .proto file to C#, based on protobuf-net, also works on Windows/Mac/Linux.


参考资料