好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

PHP环境中使用ProtoBuf数据格式

syntax="proto3";
package test;
message Person{
 string name=1;//姓名
 int32 age=2;//年龄
 bool sex=3;//性别
}
tar -zxvf protobuf-php-3.5.1.tar.gz
cd protobuf-3.5.1
./configure --prefix=/opt/soft/protobuf
make
make install
<?php
include 'vendor/autoload.php';
include 'GPBMetadata/Person.php';
include 'Test/Person.php';

$person = new Test\Person();
$person->setName("lailaiji");
$person->setAge("28");
$person->setSex(true);
$data = $person->serializeToString();
file_put_contents('data.bin',$data);
<?php
include 'vendor/autoload.php';
include 'GPBMetadata/Person.php';
include 'Test/Person.php';
$bindata = file_get_contents('./data.bin');
$person = new Test\Person();
$person->mergeFromString($bindata);
echo $person->getName();

以上就是PHP环境中使用ProtoBuf数据格式的详细内容!

查看更多关于PHP环境中使用ProtoBuf数据格式的详细内容...

  阅读:41次