Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda