[我想知道是否有一种快速的方法来从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
方法,但是没有运气。我也不知道这是否是其预定目的。
$feature->serializeToJsonString();