windows下php使用protobuf

1、下载protobufc

https://github.com/google/protobuf/releases/download/v3.5.0/protoc-3.5.0-win32.zip

解压后放d:\protoc,将d:\protoc\bin加入PATH

2、下载使用drslump/Protobuf-PHP

进入https://github.com/drslump/Protobuf-PHP,点击clone or download按钮,下载后放E:\source\Protobuf-PHP

3、转换proto文件为php文件

test2.proto也放在E:\source\Protobuf-PHP

syntax = "proto3";

message PhoneNumber {

string number = 1;

int32 type = 2;

}

message Person {

string name = 1;

int32 id = 2;

string email = 3;

repeated PhoneNumber phone = 4;

double money = 5;

}

message AddressBook {

repeated Person person = 1;

}

-------------------------------------------------------------------------------------------

e:

cd source/Protobuf-PHP-master

protoc --plugin=protoc-gen-php=.\protoc-gen-php.php --proto_path=./ --php_out=./out ./test2.proto

生成的文件放的out目录里

GPBMetadata/test2.php

AddressBook.php

Person.php

PhoneNumber.php