Google ProtoBuf 一种语言无关、平台无关、可扩展的序列化结构数据的方法

Google ProtoBuf是一种语言无关、平台无关的序列化结构数据的方法,广泛应用于数据通信、存储等。ProtoBuf支持Java、Python、Objective-C、C++等语言,并在proto3版本中增加了Dart、Go、Ruby、C#支持。它通过定义.proto文件来结构化数据,具有向后兼容性。相比XML,ProtoBuf更简单、更小、更快。ProtoBuf历史始于解决指数服务器请求/响应协议的复杂性问题,如今已成为Google内部数据的通用语言。
摘要由CSDN通过智能技术生成
ProtoBuf

Welcome to the developer documentation for protocol buffers – a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more.

protocol buffers 是一种语言无关、平台无关、可扩展的序列化结构数据的方法。它可用于(数据)通信协议、数据存储等。

官方网址:https://developers.google.cn/protocol-buffers/

Guide:https://developers.google.cn/protocol-buffers/docs/overview

github地址:https://github.com/protocolbuffers/protobuf

支持的语言

Protocol buffers currently support generated code in Java, Python, Objective-C, and C++. With our new proto3 language version, you can also work with Dart, Go, Ruby, and C#, with more languages to come.

它支持以下语言:

  • Java
  • Python
  • Objective-C
  • C++

在新的proto3版本中,又支持了:

  • Dart
  • Go
  • Ruby
  • C#
proto是如何工作的(C++举例)?

You specify how you want the information you’re serializing to be structured by defining protocol buffer message types in .proto files. Each protocol buffer message is a small logical record of information, containing a series of name-value pairs. Here’s a very basic example of a .proto file that defines a message containing information about a person:

在类型为.proto的文件中定义你想要如何序列化结构数据的方法,举个例子如下:

message Person {
   
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
   
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
   
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phone = 4;
}

As you can see, the message format is simple – each message type has one or more uniquely numbered fields, and each field has a name and a value type, where value types can be numbers (integer or floating-point), booleans, strings, raw bytes, or even (as in the example above) other protocol buffer message types, allowing you to structure your data hierarchically. You can specify optional fields, required fields, and repeated fields. You can find more information about writing .proto files in the Protocol Buffer Language Guide.

消息格式很简单,每个消息类型都有一个或多个字段,每个字段都有一个名字和它的值类型,这个值类型可以是很多(整数,浮点,布尔,字符串,原始字节,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值