Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda