I am wondering if there is a quick way to get a PHP array from the \Google\Protobuf\Internal\Message
object that is returned from the GRPC client without having to explicitly map the response objects fields to an array.
The GRPC tutorial seems to get the fields by calling their getters:
$point = new Routeguide\Point();
$point->setLatitude(409146138);
$point->setLongitude(-746188906);
// $feature is the response
list($feature, $status) = $client->GetFeature($point)->wait();
// Calling getters here
print sprintf("Found %s \n at %f, %f\n", $feature->getName(),
$feature->getLocation()->getLatitude() / COORD_FACTOR,
$feature->getLocation()->getLongitude() / COORD_FACTOR);
Is there a faster way? I see the decode()
method on the \Google\Protobuf\Internal\Message
class but haven't had luck with getting it to work. I don't know if that is its intended purpose either.
I know it's a bit late but for anyone looking for the answer today,
below is what I do to serialize the gRPC object response directly to a json object:
$feature->serializeToJsonString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With