Protocol Buffer 是什么
Protocol Buffer 是 Google 提供的一种数据序列化协议,是一种轻便高效的结构化数据存储格式,可以用于结构化数据序列化,很适合做数据存储或 RPC 数据交换格式。它可用于通讯协议、数据存储等领域的语言无关、平台无关、可扩展的序列化结构数据格式。
为何使用 Protocol Buffer
Protocol Buffer 属于二进制协议,解析处理更快
1. 安装 js 包 google-protobuf
npm i google-protobuf -s
2. 下载 protoc
编译工具,用于编译 .proto 文件
https://github.com/protocolbuffers/protobuf/releases
下载 protoc-3.14.0-win64.zip
3. 编写 message.proto
proto 文件写法参考: