当前位置:网站首页>tp6 使用 ProtoBuf
tp6 使用 ProtoBuf
2022-07-29 06:33:00 【清木Moyu】
以下为无需c扩展版本
window下下载win32或者win64版本,mac下载osx版本
解压后得到文件夹(以mac为例)protoc-21.4-osx-x86_64,可运行的脚本protoc在bin文件夹下
编写proto消息类型,保存为person.proto
syntax="proto3";
package proto;
message Person{
string name=1;
int32 age=2;
}
执行脚本,生成类库
protoc --php_out=protobuf/compile --proto_path=protobuf/proto protobuf/proto/*.proto
# 第一个路径为 生成文件的位置及编译成哪种语言,第二个为存储proto文件的位置,第三个表示当前文件下所有proto文件
# proto文件需要在同一目录下,不能在子文件夹下
执行后生成文件
GPBMetadata/Person.php
Proto/Person.php
在php中使用
当前项目下安装依赖扩展,安装composer依赖扩展
composer require google/protobuf
注意国内镜像可能下载失败,可以将镜像改为 https://repo.packagist.org 后重新执行
序列化
......
use GPBMetadata/Person;
use Proto/Person;
......
$person = new Person();
$person->setName("张三");
$person->setAge(27);
$data = $person->serializeToString();
......
反序列化
......
use GPBMetadata/Person;
use Proto/Person;
......
$data = $this->request->param('protodata');
$person = new Person();
$person->mergeFromString($data);
$person->getName();
$person->getAge();
......
边栏推荐
- Relative date used by filter in salesforce
- VMware16创建虚拟机:无法创建新虚拟机,不具备执行此操作的权限
- dba
- Leetcode-1331: array ordinal conversion
- Connecting PHP 7.4 to Oracle configuration on Windows
- Vscode remote debugging PHP solution through remotessh and Xdebug
- [solution] error: lib/bridge_ generated. dart:837:9: Error: The parameter ‘ptr‘ of the method ‘FlutterRustB
- 模拟卷Leetcode【普通】222. 完全二叉树的节点个数
- Kubernetes (五) ---------部署 Kubernetes Dashboard
- MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of
猜你喜欢
Nodejs安装教程
个人博客系统(附源码)
spark学习笔记(七)——sparkcore核心编程-RDD序列化/依赖关系/持久化/分区器/累加器/广播变量
vim文本编辑器的一些使用小技巧
Vite3.0 has been released, can you still roll it (list of new features)
数组的子集能否累加出K
ECCV 2022 lightweight model frame Parc net press apple mobilevit code and paper Download
MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of
建木持续集成平台v2.5.2发布
WPF简单登录页面的完成案例
随机推荐
聊天机器人有何用处?有何类型?看完这些就明白了!
Unity exploration plot access design analysis & process + code specific implementation
[CF1054H] Epic Convolution——数论,卷积,任意模数NTT
ECCV 2022 lightweight model frame Parc net press apple mobilevit code and paper Download
Simulation volume leetcode [general] 150. evaluation of inverse Polish expression
vim文本编辑器的一些使用小技巧
Vite3.0 has been released, can you still roll it (list of new features)
基于C语言设计的学生成绩排名系统
VMware16创建虚拟机:无法创建新虚拟机,不具备执行此操作的权限
Excel文件读写(创建与解析)
最新百亿量化私募名单
基于C语言实现图书借阅管理系统
dba
Cesium reflection
Unity发送Post请求给GoLang服务端解析并返回
Flink real-time warehouse DWD layer (transaction domain - additional purchase dimension degradation processing) template code
Vmware16 create virtual machine: cannot create a new virtual machine, do not have permission to perform this operation
Excerpts from good essays
DM data guard cluster setup
ETL为什么经常变成ELT甚至LET?