centraldesktop / Protobuf-PHP

PHP implementation of Google's Protocol Buffers with a protoc plugin compiler
http://drslump.github.com/Protobuf-PHP/
MIT License
27 stars 25 forks source link

execution hangs #27

Open electricBonfire opened 6 years ago

electricBonfire commented 6 years ago

Very new to protocol buffers so sorry if this is something simple on my end...

I have installed this repo via composer. I have also installed protoc via homebrew.

When I run the following command execution hangs with no output: ./vendor/bin/protoc-gen-php.php -o ./build -i nyct-subway.proto

I have downloaded this file and removed the .txt extension: http://datamine.mta.info/sites/all/files/pdfs/nyct-subway.proto.txt

Is there something I am missing? The first 2 lines of the .proto.txt file are: option java_package = "com.google.transit.realtime"; import "gtfs-realtime.proto";

Do I need to download these dependencies? Is this even a valid .proto file for use with protobuf-php?

electricBonfire commented 6 years ago

Well made minor headway. I found the gtfs-realtime.proto file. I also changed my execution to: ./vendor/bin/protoc-gen-php.php -vvv -o ./build -i . nyct-subway.proto

Now I get the error:

[libprotobuf WARNING google/protobuf/compiler/parser.cc:546] No syntax specified for the proto file: nyct-subway.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)

--php_out: nyct-subway.proto: Can only generate PHP code for proto3 .proto files. Please add 'syntax = "proto3";' to the top of your .proto file.

When I add syntax = "proto3"; I get the following error: nyct-subway.proto:12:12: Explicit 'optional' labels are disallowed in the Proto3 syntax. To define 'optional' fields in Proto3, simply remove the 'optional' label, as fields are 'optional' by default.

When I remove all of the optional from the file I get the following errors:

nyct-subway.proto: Extensions in proto3 are only allowed for defining options. nyct-subway.proto: Required fields are not allowed in proto3. nyct-subway.proto: The first enum value must be zero in proto3.</error >

It seems like this file is for an older version of the syntax (?) However the first error stated: --php_out: nyct-subway.proto: Can only generate PHP code for proto3 .proto files

dstevenson commented 6 years ago

This project is currently using google protocol buffers v2. Right now by default homebrew will install protobuf v3

electricBonfire commented 6 years ago

Ok thanks, I will try to download v2

electricBonfire commented 6 years ago

That did the trick! Thank you!

electricBonfire commented 6 years ago

I am running the following ./vendor/bin/protoc-gen-php.php -o ./build -i . --protoc=/usr/local/opt/protobuf@2.6/bin/protoc nyct-subway.proto

It is reading the nyct-subway.proto file and outputting gtfs-realtime.php in the bin dir.

However, I am not seeing any of the messages that are located inside the nyct file.

I am trying to access the NyctFeedHeader extension, but it is returning NULL, and I do not see any references to it inside the newly created gtfs-realtime file.

When I diff the original gtfs-realtime.php file and the newly created one, there is very little difference.

dstevenson commented 6 years ago

Do you have a copy of the gtfs-realtime.proto file you can attach here?

electricBonfire commented 6 years ago

gtfs-realtime.proto.txt

nyct-subway.proto.txt

File created by running protoc: gtfs-realtime.php.txt