当前位置:网站首页>## 简讲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若被删除的话将可能导致兼容性的问题。
边栏推荐
- disabledDate 日期选择器 datePicker
- Collision, character controller, Cloth components (cloth), joints in the Unity physics engine
- [问题已处理]-jenkins流水线checkout超时
- 无法导入torchvision.io.read_image
- LeetCode刷题记录(2)
- Media query, rem mobile terminal adaptation
- Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images
- 单片机原理与应用复习
- D39_ coordinate transformation
- Cocos Creator Mini Game Case "Stick Soldier"
猜你喜欢

多线程之传递参数

The 25 best free games on mobile in 2020

Cocos Creator Mini Game Case "Stick Soldier"

DisabledDate date picker datePicker

VRRP overview and experiment
![[问题已处理]-jenkins流水线checkout超时](/img/3d/c14276d2b5ce18fc3d1288abb059c0.png)
[问题已处理]-jenkins流水线checkout超时

What are some things that you only know when you do operation and maintenance?

selenium学习

DevOps-了解学习

DevOps process demo (practical record)
随机推荐
ALC experiment
Mina disconnects and reconnects
Growth: IT Operations Trends Report
通过反射获取Class对象的四种方式
Come, come, let you understand how Cocos Creator reads and writes JSON files
One-arm routing experiment and three-layer switch experiment
设置文本向两边居中展示
Pytorch分布式并行处理
js 使用雪花id生成随机id
Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"
网络协议基础-学习笔记
Teach you simple steps to achieve industrial raspberries pie properly installed RS232 USB drive
LinkSLA insists that users come first and creates a sustainable operation and maintenance service plan
浏览器兼容汇总
product learning materials
input detailed file upload
Difference between link and @improt
wc, grep, tar, vi/vim
link 和@improt的区别
Will intelligent operation and maintenance replace manual operation and maintenance?