Nothing Special   Β»   [go: up one dir, main page]

Skip to content

SRWieZ/grpc-protoset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gRPC Protoset Converter

Latest Stable Version Total Downloads License PHP Version Require

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:

πŸ“ License

gRPC Protoset Converter is licensed under the MIT License. See LICENSE for more information.

About

A simple PHP library to convert a protoset file to proto files

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages