当前位置:网站首页>## 简讲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若被删除的话将可能导致兼容性的问题。
边栏推荐
- 单片机原理与应用复习
- Tencent greetings function SCF - entry instructions
- [Problem has been resolved]-Virtual machine error contains a file system with errors check forced
- Nacos集群搭建
- 邮件管理 过滤邮件
- Problems encountered in installing Yolo3 target detection module in Autoware
- cs231n学习记录
- D39_ coordinate transformation
- VLAN is introduced with the experiment
- Cloud Computing Basics - Study Notes
猜你喜欢
随机推荐
Into the pre-service, thought they play so flowers
Proprietary host CDH
Introduction to Network Layer Protocols
网络协议基础-学习笔记
DevOps process demo (practical record)
Operation and maintenance engineer, come and pick up the wool
Xiaodu Xiaodu is here!
Programmers should understand I/O this way
Teach you simple steps to achieve industrial raspberries pie properly installed RS232 USB drive
前置++和后置++的区别
请问下通过flink sql读取hologres 的两张表的 binlog,然后如何进行join?
DevOps - Understanding Learning
Tencent Internal Technology: Evolution of Server Architecture of "The Legend of Xuanyuan"
selenium学习
js判断文字是否超过区域
BIO,NIO,AIO实践学习笔记(便于理解理论)
ROS2下使用ROS1 bag的方法
Advantages of overseas servers
Mina's long and short connections
DisabledDate date picker datePicker