protobuf总结

1、protobuf是什么?

protobuf(protocol buffers)是一种语言中立,平台无关,可扩展的序列化数据的格式,可以用于通信协议,数据存储等。

protobuf 相比于xml,json更加小巧,灵活,简单。

protobuf很适合做数据存储或RPC数据交换格式。

2、protobuf3和protobuf2

 proto2:

message helloworld 
{ 
   required int32     id = 1;  // ID 
   required string    str = 2;  // str 
   optional int32     opt = 3;  //optional field 
}

  

proto 3 :

syntax = "proto3";

message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 result_per_page = 3;
}

  

 

3、命名规范

驼峰命名法

 

引用:https://halfrost.com/protobuf_encode/#protocolbuffer

posted @ 2019-03-15 17:34  liubiaos  阅读(322)  评论(0编辑  收藏  举报