Tom*_*rtz 5 php protocol-buffers grpc
我想知道是否有一种快速方法可以\Google\Protobuf\Internal\Message从 GRPC 客户端返回的对象中获取 PHP 数组,而无需将响应对象字段显式映射到数组。
GRPC教程似乎通过调用它们的 getter 来获取字段:
$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);
Run Code Online (Sandbox Code Playgroud)
有更快的方法吗?我decode()在\Google\Protobuf\Internal\Message课堂上看到了该方法,但没有运气让它发挥作用。我也不知道这是否是它的预期目的。
我知道现在有点晚了,但对于今天寻找答案的人来说,
下面是我将 gRPC 对象响应直接序列化为 json 对象的方法:
$feature->serializeToJsonString();
Run Code Online (Sandbox Code Playgroud)