Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
Convert GRPC protobuf response to PHP array without mapping

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.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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();
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!