srwiez / grpc-protoset
Convert a protoset file to a directory of .proto files
Fund package maintenance!
SRWieZ
Requires
- php: ^8.3
- ext-grpc: *
- google/protobuf: ^4.28
Requires (Dev)
- laravel/pint: ^1.18
- pestphp/pest: ^3.5
- phpstan/phpstan: ^2.0
README
A simple PHP library to convert a protoset file to proto files.
If you're here, you likely attempted to use a gRPC API and need to generate a PHP client. However, you may be stuck because you have a protoset file instead of a proto file.
This library will assist you in converting the protoset file to proto files.
It works well with gRPC servers that have the reflection service enabled. To learn more, check out the use case example below.
🚀 Installation
composer require srwiez/grpc-protoset
📚 Usage
Either use the ProtosetConverter
class directly.
use SRWieZ\GrpcProtoset\ProtosetConverter; $protoset = new ProtosetConverter(); $protoset->setOutputDir('./proto'); $protoset->convert('starlink.protoset');
or use the script provided by the package.
php cli/converter.php "starlink.protoset" ./proto
or if you have installed the package globally, you can use the following command:
protoset-converter "starlink.protoset" ./proto
🎁 Use case example (Starlink)
How to generate a PHP client for the Starlink API.
You will need to install the following dependencies:
brew install protobuf brew install grpc brew install grpcurl
First, get the protoset file from your Starlink device.
grpcurl -plaintext -protoset-out "starlink.protoset" "192.168.100.1:9200" describe SpaceX.API.Device.Device
Then, convert the protoset file to proto files.
protoset-converter "starlink.protoset" ./proto
Finally, generate the PHP client.
protoc --php_out=./generated/ proto/spacex/api/device/device.proto
Bonus, edit your composer.json file to autoload the generated PHP client.
{ "autoload": { "psr-4": { "SpaceX\\API\\": "generated/SpaceX/API", "GPBMetadata\\Spacex\\Api\\": "generated/GPBMetadata/Spacex/Api" } } }
📋 TODO
Contributions are welcome!
- Write tests by using the starlink protoset file
🤝 Contributing
Clone the project and run composer update
to install the dependencies.
Before pushing your changes, run composer qa
.
This will run pint (code style), phpstan (static analysis), and pest (tests).
👥 Credits
gRPC Protoset Converter was created by Eser DENIZ.
The following projects inspired this library and served as a reference:
- https://github.com/ewilken/starlink-rs
- https://github.com/sparky8512/starlink-grpc-tools
- https://github.com/fullstorydev/grpcurl
📝 License
gRPC Protoset Converter is licensed under the MIT License. See LICENSE for more information.