2. 适用场景
"Protocol Buffers are not designed to handle large messages."。protobuf对于1M以下的message有很高的效率,但是当message是大于1M的大块数据时,protobuf的表现不是很好,请合理使用。
https://blog.youkuaiyun.com/modiziri/article/details/49618927
Protocol Buffers官方文档(proto3语言指南)
http://www.mamicode.com/info-detail-2311280.html
protobuf是Google开发的一个序列化框架,类似XML,JSON,基于二进制,比传统的XML表示同样一段内容要短小得多。通过protobuf,可以很轻松的调用相关方法来完成业务数据的序列化与反序列化。
protobuf repeated类型相当于std的vector,可以用来存放N个相同类型的内容,文章将简单介绍protobuf repeated的使用。
首先定义一个protobuf结构,如下:
proto3
字段规则移除了 “required”,所有非repeated的字段都默认为optional
message Person {
required int32 age = 1;
required string name = 2;
}
message Family {
repeated Person person = 1;
}
- int32、uint32、int64、uint64和bool等类型之间是兼容的,sint32和sint64是兼容的,string和bytes是兼容的,fixed32和sfixed32,以及fixed64和sfixed64之间是兼容的,这意味着如果想修改原有字段的类型时,为了保证兼容性,只能将其修改为与其原有类型兼容的类型,否则就将打破新老消息格式的兼容性。
- optional和repeated限定符也是相互兼容的。
使用protobuf实现任意文件的传输
https://blog.youkuaiyun.com/sanduan168/article/details/80452649
PB使用http协议、https协议(简单便捷)
https://blog.youkuaiyun.com/softvery/article/details/87556945
PB协议说明与使用
https://blog.youkuaiyun.com/mao834099514/article/details/53906749
proto3 中的 map 类型
https://www.cnblogs.com/tangxin-blog/p/8314563.html