如何在PHP中读取GTFS协议缓冲区?

Sky*_*yNT 7 php protocol-buffers gtfs

我有一个GTFS协议缓冲消息(VehiclePosition.pb),及相应的协议格式(GTFS-realtime.proto),我想单独读取PHP消息(是,即使可能吗?).

我查看了Google的python教程https://developers.google.com/protocol-buffers/docs/pythontutorial和编码文档https://developers.google.com/protocol-buffers/docs/encodinghttps:// github. com/maxious/ACTBus-ui/tree/master/lib/Protobuf-PHP,但我很难概念化正在发生的事情.我想我明白gtfs-realtime.php是gtfs-realtime.proto中定义的编码的编译指令集(请纠正我,如果我错了),但我不知道如何让它解码VehiclePosition.pb.另外,gtfs-realtime.php(或者python等价物)的依赖关系是什么?如果我想要做的只是阅读VehiclePosition.pb,还有什么我需要编译自己或任何不是简单的PHP脚本的东西吗?

谢谢.

edm*_*rce 0

我会假设与此片段类似的内容:

<?php
require_once 'DrSlump\Protobuf.php';

use DrSlump\Protobuf;

$data = file_get_contents('data.pb');
$person = new Tutorial\Person($data);
echo $person->getName();
Run Code Online (Sandbox Code Playgroud)

取自手册页:http://drslump.github.io/Protobuf-PHP/protobuf-php.3.html

在此步骤之前,我认为您需要使用 CLI 工具生成 PHP 类,如下所述:http ://drslump.github.io/Protobuf-PHP/protoc-gen-php.1.html

所以大致如下:

protoc-gen-php gtfs-realtime.proto
Run Code Online (Sandbox Code Playgroud)