当前位置:网站首页>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();
......边栏推荐
- [C language brush leetcode] 1054. Bar code with equal distance (m)
- Flink real-time warehouse DWD layer (order placing multiple tables to realize join operation) template code
- 我的个人网站不让接入微信登录,于是我做了这个
- ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法
- HJ37 统计每个月兔子的总数 斐波那契数列
- SSH免密登录-两台虚拟机建立免密通道 双向信任
- JS 鸡生蛋与蛋生鸡问题,Object与Function究竟谁出现的更早?Function算不算Function的实例?
- 要不要满足客户所有的需求
- MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of
- Student achievement ranking system based on C language design
猜你喜欢

Flink实时仓库-DWD层(流量域)模板代码

Record - step on the pit - real-time data warehouse development - doris/pg/flink

接口测试实战项目03:执行测试用例

leetcode-592:分数加减运算

Unity exploration plot access design analysis & process + code specific implementation

Vite3.0都发布了,你还能卷得动吗(新特性一览)

SSH免密登录-两台虚拟机建立免密通道 双向信任

微信小程序的反编译

Is online legend software testing training really so black hearted? Are they all scams?

Leetcode 879. profit plan
随机推荐
JS 鸡生蛋与蛋生鸡问题,Object与Function究竟谁出现的更早?Function算不算Function的实例?
Flink实时仓库-DWD层(流量域)模板代码
Vite3.0 has been released, can you still roll it (list of new features)
Personal blog system (with source code)
CVPR2021| 基于自监督学习的多视图立体匹配 (CVPR2021)
外包干了3年,跳槽后转自动化测试工资是原来的2倍,秘诀原来是......
Flink real-time warehouse DWD layer (transaction domain - additional purchase dimension degradation processing) template code
330. 按要求补齐数组
H3C_利用设置缺省静态路由优先级实现出口双线路的主备功能
Revolution of game assets
Excerpts from good essays
Pod基本介绍
Unity发送Post请求给GoLang服务端解析并返回
ECCV 2022 lightweight model frame Parc net press apple mobilevit code and paper Download
WPF简单登录页面的完成案例
Image noise and matrix inversion
buck电路boot电容短路和断路实测波形
Vmware16 create virtual machine: win11 cannot be installed
Flink实时仓库-DWD层(kafka-关联mysql的lookup join)模板代码
IO stream - file - properties