将GRPC protobuf响应转换为PHP数组而不进行映射

问题描述 投票:2回答:1

[我想知道是否有一种快速的方法来从GRPC客户端返回的\Google\Protobuf\Internal\Message对象中获取PHP数组,而不必将响应对象字段显式映射到数组。

GRPC tutorial似乎是通过调用其获取器来获取字段的:

$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);

有更快的方法吗?我在decode()类上看到了\Google\Protobuf\Internal\Message方法,但是没有运气。我也不知道这是否是其预定目的。

php protocol-buffers grpc
1个回答
0
投票
我知道现在有点晚了,但是对于今天寻找答案的任何人,下面是我将gRPC对象响应直接序列化为json对象的操作:

$feature->serializeToJsonString();

© www.soinside.com 2019 - 2024. All rights reserved.