当前位置:网站首页>## 简讲protobuf-从原理到使用
## 简讲protobuf-从原理到使用
2022-08-05 05:25:00 【木棉-小健】
简讲protobuf-从原理到使用
protobuf是google团队开发的用于高效存储和读取结构化数据的工具。什么是结构化数据呢,正如字面上表达的,就是带有一定结构的数据。
xml、json也可以用来存储此类结构化数据,但是使用protobuf表示的数据能更加高效,并且将数据压缩得更小,大约是json格式的1/10,xml格式的1/20。
定义message结构
//关卡目标单个目标数据
protobuf将一种结构称为一个message类型
message GoalItem {
int32 id = 1; //目标id
int32 itemType = 2; //奖励类型
int32 itemId = 3; //奖励id
int32 itemNum = 4; //奖励数量
int32 status = 5; //0未完成,1完成未领取,2完成已领取
}
我这里以游戏关卡奖励为例
Field最前面的required,optional,repeated是这个Filed的规则,分别表示该数据结构中这个Filed有且只有1个,可以是0个或1个,可以是0个或任意个。optional后面可以加default默认值,如果不加,数据类型的默认为0,字符串类型的默认为空串。repeated后面加[packed=true]会使用新的更高效的编码方式。
注意:使用required规则的时候要谨慎,因为以后结构若发生更改,这个Filed若被删除的话将可能导致兼容性的问题。
边栏推荐
- Mina's long and short connections
- 深入分析若依数据权限@datascope (注解+AOP+动态sql拼接) 【循序渐进,附分析过程】
- H5 的浏览器存储
- [ingress]-ingress exposes services using tcp port
- numpy.random使用文档
- By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital
- Four ways to obtain Class objects through reflection
- Met with the browser page
- BIO,NIO,AIO实践学习笔记(便于理解理论)
- Cloud Computing Basics - Study Notes
猜你喜欢

Mina的长连接和短连接

Passing parameters in multiple threads

transport layer protocol

BIO, NIO, AIO practical study notes (easy to understand theory)

GetEnumerator method and MoveNext and Reset methods in Unity
![[问题已处理]-虚拟机报错contains a file system with errors check forced](/img/07/1222a44dd52b359bf7873e6f3b7ebf.png)
[问题已处理]-虚拟机报错contains a file system with errors check forced

Problems encountered in installing Yolo3 target detection module in Autoware

深夜小酌,50道经典SQL题,真香~

NB-IOT智能云家具项目系列实站

Operation and maintenance engineer, come and pick up the wool
随机推荐
Detailed explanation of ten solutions across domains (summary)
Mina的长连接和短连接
vscode笔记
Tencent greetings function SCF - entry instructions
cs231n学习记录
初识网页与浏览器
DevOps流程demo(实操记录)
Seven Ways to Center a Box Horizontally and Vertically
document.querySelector()方法
Transformer interprets and predicts instance records in detail
Alibaba Cloud Video on Demand
滚动条问题,未解决
Native JS takes you to understand the implementation and use of array methods
单片机期末复习大题
Mina's long and short connections
记录vue-页面缓存问题
LeetCode practice and self-comprehension record (1)
Nacos集群的搭建过程详解
Transformer详细解读与预测实例记录
Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images