当前位置:网站首页>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();
......边栏推荐
- 以太网接口介绍
- DM data guard cluster setup
- Spark Learning Notes (VII) -- spark core core programming - RDD serialization / dependency / persistence / partition / accumulator / broadcast variables
- WPF嵌套布局案例
- 2022-07-28:以下go语言代码输出什么?A:AA;B:AB;C:BA;D:BB。 package main import ( “fmt“ ) func main() { f
- 我的个人网站不让接入微信登录,于是我做了这个
- Can MySQL export tables regularly?
- 约瑟夫环问题
- Operator3-设计一个operator
- Pod基本介绍
猜你喜欢

CAN&CANFD综合测试分析软件LKMaster与PCAN-Explorer 6分析软件的优势对比

微信小程序的反编译

WPF简单登录页面的完成案例

Thread synchronization - producers and consumers, tortoise and rabbit race, dual thread printing

我的创业邻居们

MVFuseNet:Improving End-to-End Object Detection and Motion Forecasting through Multi-View Fusion of

Leetcode 879. profit plan

最新百亿量化私募名单

线程同步—— 生产者与消费者、龟兔赛跑、双线程打印

vim文本编辑器的一些使用小技巧
随机推荐
Relative date used by filter in salesforce
WPF嵌套布局案例
Analog volume leetcode [normal] 093. Restore IP address
城市花样精~侬好!DESIGN#可视化电台即将开播
2022年SQL经典面试题总结(带解析)
约瑟夫环问题
【C语言刷LeetCode】67. 二进制求和(E)
Leetcode-592: fraction addition and subtraction
[CF1054H] Epic Convolution——数论,卷积,任意模数NTT
Flink real time warehouse DWD layer (traffic domain) template code
Student status management system based on C language design
Cesium reflection
OCR光学字符识别方法汇总
Cvpr2022oral special series (I): low light enhancement
【C语言刷LeetCode】2332. 坐上公交的最晚时间(M)
Simulation volume leetcode [normal] 222. number of nodes of complete binary tree
mysql查询区分大小写
最新百亿量化私募名单
解决CSDN因版权不明而无法发布博客的问题
Federal learning backdoor attack summary (2019-2022)