mobilitydata / gtfs-realtime-bindings Goto Github PK
View Code? Open in Web Editor NEWLanguage bindings generated from the GTFS Realtime protocol buffer spec for popular languages.
License: Apache License 2.0
Language bindings generated from the GTFS Realtime protocol buffer spec for popular languages.
License: Apache License 2.0
Version: 0.0.6
Python version: 3.9
OS: Fedora 33
Issue:
GTFS realtime bindings for Python are reporting a deprecation warning for EnumDescriptor(), EnumValueDescriptor(), FileDescriptor(), FieldDescriptor(), Descriptor()
Example:
WARNING - .../local/lib/python3.9/site-packages/google/transit/gtfs_realtime_pb2.py:381: DeprecationWarning: Call to deprecated create function FieldDescriptor(). Note: Create unlinked descriptors is going to go away. Please use get/find descriptors from generated code or query the descriptor_pool.
_descriptor.FieldDescriptor(
I'm in the process of upgrading our environment to python 3, but gtfs-realtime-bindings refuses to install. This is what I get:
$ pip install --upgrade gtfs-realtime-bindings
Collecting gtfs-realtime-bindings
Downloading https://files.pythonhosted.org/packages/c8/ae/a62dba2b0eef515ce803ceb9329c4d196127e10d6e218ca9a46b3b0610fe/gtfs-realtime-bindings-0.0.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extern.six.moves import filterfalse, map
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/setuptools/extern/__init__.py", line 1, in <module>
from pkg_resources.extern import VendorImporter
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2927, in <module>
@_call_aside
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2913, in _call_aside
f(*args, **kwargs)
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
add_activation_listener(lambda dist: dist.activate())
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 956, in subscribe
callback(dist)
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2952, in <lambda>
add_activation_listener(lambda dist: dist.activate())
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2515, in activate
declare_namespace(pkg)
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2097, in declare_namespace
_handle_ns(packageName, path_item)
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2047, in _handle_ns
_rebuild_mod_path(path, packageName, module)
File "/opt/regularroutes/virtualenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2066, in _rebuild_mod_path
orig_path.sort(key=position_in_sys_path)
AttributeError: '_NamespacePath' object has no attribute 'sort'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-cbbnx7ju/gtfs-realtime-bindings/
Python 3.5.2 (default, Nov 23 2017), pip 10.0.1, Setuptools 20.7.0. Freshly generated ubuntu/xenial64 box in Vagrant.
Wouldn't be surprised to find something wrong with my environment, but 46 other python libraries installed ok, so something looks special about this one.
This will be very useful for academic and research-focussed transport planners.
My package co-author @richardellison has added gtfs import functionality:
ropensci/stplanr#34
Could that could provide a basis for official support?
I'm fetching feed data from a URL endpoint of the form <baseUrl>/<feedName>.proto
, but for some reason I get an "invalid wire type" error when I do GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body)
in Node.js. I'm using the example code from the Node.js README:
var GtfsRealtimeBindings = require('gtfs-realtime-bindings');
var request = require('request');
var requestSettings = {
method: 'GET',
url: '<baseUrl>/<feedName>.proto',
encoding: null,
};
request(requestSettings, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body);
feed.entity.forEach(function(entity) {
if (entity.trip_update) {
console.log(entity.trip_update);
}
});
}
});
// <Buffer 68 65 61 64 65 72 20 7b 0a 20 20 67 74 66 73 5f 72 65 61 6c 74 69 6d 65 5f 76 65 72 73 69 6f 6e 3a 20 22 31 2e 30 22 0a 20 20 69 6e 63 72 65 6d 65 6e ... 37282 more bytes> object
// C:\Users\Chris Marais\code\js\protobuf\node_modules\gtfs-realtime-bindings\node_modules\protobufjs\src\reader.js:375
throw Error("invalid wire type " + wireType + " at offset " + this.pos);
^
// Error: invalid wire type 7 at offset 12
Is the array buffer encoded incorrectly perhaps? Unfortunately I'm unable to share the data, but I can confirm that it conforms to the GTFS realtime specification
When looking at the gtfs-realtime.proto file, field names use underscores like active_period in Alert or current_stop_sequence in VehiclePosition.
Likewise, the ASCII representation example shows all field names with underscores: https://developers.google.com/transit/gtfs-realtime/examples/trip-updates-full As does the reference on both https://gtfs.org/reference/realtime/v2/ and https://developers.google.com/transit/gtfs-realtime/reference
However, to use the nodejs bindings (I haven't checked the others), it requires all attributes to be in camelCase and this applies for both input and output, so you get activePeriod and currentStopSequence.
We use fromObject to convert a JSON GTFS-RT representation into Protobuf, and this was developed using underscores in field names. We can pass the data through a converter to change to camelCase, but wondering if I am missing something here? Shouldn't documentation (linked above) either refer to fields in camelCase or the bindings use underscores for both input/output?
It also means the example code here for nodejs doesn't work and should actually be entity.tripUpdate?
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body);
feed.entity.forEach(function(entity) {
if (entity.trip_update) {
console.log(entity.trip_update);
}
});
Furthermore, looking to confirm that camelCase on field names is expected for GTFS-RT feeds globally? Passing ones through the FeedMessage.decode function definitely makes this seem the case.
Hello,
I would like to request for a Google team to create a GTFS-realtime-bindings example for Python 3 based bindings from start to finish.
The example provided doesn't even scratch the surface regarding this issue, so please help beginners like myself to be able to implement GTFS related data (such as those given by NYC MTA) for projects.
I stress this because major city transit data feeds are in GTFS format, yet the example provided doesn't even help manipulate a real world example for it.
Thanks.
.Net Framework is supported, but there is no binding for .Net Core. It would be great, if you ship the NuGet Package as a .Net Standard package, so it can be used on any platform.
Parsing a GTFS-realtime feed is shown in the README as:
var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
But for it to work it must be:
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body);
Our shop uses Python for much of our front-end web development, but our lower-level transit integrations are written exclusively in Go. Would be great to integrate with GTFS-Realtime via Go.
Full Error Message: Illegal value for Message.Field .transit_realtime.TripDescriptor.schedule_relationship: 5 (not a valid enum value)
Test Data: https://api.transport.nsw.gov.au/v1/gtfs/realtime/sydneytrains
Example: JavaScript/Node.js Sample
Successful case: https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/sydneytrains
Comment: Year, it does support for the "vehicepos data set" test case as in the test file, but seems like this bindings does not support for the data set "realtime Sydney trains"
Having an issue with the .NET version.
It does not seem to populate TripUpdate consistently. Seems when Vehicle is available TripUpdate is not populated.
Tested the same feed using JAVA code from OneBusAway and TripUpdate is there on every entity item.
What could be the reason? Any ways to get TripUpdate to populate reliably ?
I am having intermittent issues with the MTA protobuf feed. I am mostly just at a loss on how to debug and track down the issue.
The feed is here (with an MTA key; happy to share off list):
http://datamine.mta.info/mta_esi.php?feed_id=1&key=[[[MTA_API_KEY]]]
The error I get is the following. It is intermittent and there does not seem to be any pattern as to when/why it happens, though it roughly happens every 5 reads.
/Users/zzolo/Codemta-project/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/ProtoBuf.js:1987
throw(e);
^
RangeError: Offset is outside the bounds of the DataView
at DataView.getUint8 (native)
at ByteBuffer.readVarint32 (/Users/zzolo/Codemta-project/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/node_modules/bytebuffer/ByteBuffer.js:1123:25)
at ProtoBuf.Reflect.Message.decode (/Users/zzolo/Codemta-project/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/ProtoBuf.js:2111:38)
at ProtoBuf.Reflect.Field.decode (/Users/zzolo/Codemta-project/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/ProtoBuf.js:2594:46)
at ProtoBuf.Reflect.Message.decode (/Users/zzolo/Codemta-project/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/ProtoBuf.js:2139:51)
at ProtoBuf.Reflect.Field.decode (/Users/zzolo/Codemta-project/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/ProtoBuf.js:2594:46)
at ProtoBuf.Reflect.Message.decode (/Users/zzolo/Codemta-project/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/ProtoBuf.js:2137:51)
at Function.Message.decode (/Users/zzolo/Codemta-project/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/ProtoBuf.js:1982:41)
at /Users/zzolo/Codemta-project/index.js:140:49
at Array.forEach (native)
My code is essentially the same as the example here:
https://github.com/google/gtfs-realtime-bindings/tree/master/nodejs#example-code
The error appears at the line:
var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
The java bindings are pulling in a protobuf-java library from July 2018 that logs a bunch of warnings on Java 9+ due to using unsafe APIs. This has been fixed for a while now, so it would be nice to update to a newer version, maybe 3.14.0.
The current release is not available on Maven Central and JCenter is shutting down on May 1st.
Hi folks,
I hope this finds you well. Thank you very much for your work on this awesome repository. I am looking for examples how to use the bindings in node.js. Especially, I am struggling with encoding messages. I would appreciate you pointing me to any usage example?
Btw, what is the reason using gtfs-realtime-bindings.js instead of protobuf.js? Is it just the convenience that I do not need to compile the javascript files anymore or is there more magic involved?
Cheers!
Hi, i keep getting this error when trying to consume a feed
No transit_realtime.TripDescriptor+ScheduleRelationship enum is mapped to the wire-value 5
The feed i am intrested in is:
"https://gtfsrt.api.translink.com.au/feed"
could you assist?
I will show it basing on FeedHeader serialization:
new FeedHeader()
{
gtfs_realtime_version = "2.0",
incrementality = FeedHeader.Incrementality.FULL_DATASET, // FeedHeader.Incrementality.FULL_DATASET == 0
timestamp = Utils.ToUnixTime(DateTime.UtcNow)
};
After serializing by ProtoBuf it seems that incrementality value (which is equal to 0) in FeedHeader class is not serialized, because when testing feed with https://github.com/CUTR-at-USF/gtfs-realtime-validator that validator shows me error "header incrementality not populated" and when I check (in that validator) protobuf file contents:
"header": {
"gtfs_realtime_version": "2.0",
"timestamp": 1520343087
}
Same problem is i.e. with:
Check also attached file.
How to solve it? Can I control somehow which values should always be serialized even if they are null / zero / empty? I am using classess provided by Google:
Is anyone in the community using the PHP bindings in https://github.com/google/gtfs-realtime-bindings-php?
I'm hitting some issues regenerating them from the gtfs-realtime.proto, as it seems proto2 files aren't officially supported by Google's protobuf compiler. More at MobilityData/gtfs-realtime-bindings-php#4.
Hello,
I started a new Maven project, and inserted the content you gave for the dependencies inside the pom.xml.
But while creating the package (mvn package) the compilation crashed because of duplicated groupId and artifactId (from my project on one side, and from gtfs-realtime-bindings on the other side). Trying to remove one or the other duplicate did not help.
Am I missing something on how to include gtfs-rt-b in a maven package?
Thanks in advance,
regards,
Xavier
It seems that the Python bindings are not compatible with Python 3.
Python 3.4.3 (default, Jun 29 2015, 12:16:01)
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.transit import gtfs_realtime_pb2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/site-packages/google/transit/gtfs_realtime_pb2.py", line 22, in <module>
from google.protobuf import reflection as _reflection
File "/usr/lib/python3.4/site-packages/google/protobuf/reflection.py", line 68, in <module>
from google.protobuf.internal import python_message
File "/usr/lib/python3.4/site-packages/google/protobuf/internal/python_message.py", line 848
except struct.error, e:
^
SyntaxError: invalid syntax
I was running into the same Python 3 problems as others. I see that it's been fixed and this package has been bumped to 0.0.5.
PyPI version is still 0.0.4 and contains the Python 3 bug.
gtfs-realtime-bindings is severely out of date (4 years) and the old, old version of protobuf.js is causing a lot of headaches since the current documentation doesn't reflect pbjs 2.0.5 (the package dependency published on npm)
Please republish the newer version of the package with the updated protobuf dependency, thank you!
Trying to use the NodeJS bindings for a React Native project, but both the yarn and npm registries have an older version in which the version of protobuf.js is 2.0.5. This causes issues because that version uses fs, which isn't available for React Native. The package.json in this repo has the version set to 6.7.3, which works in React Native, but there's no release tag for it, so I can't use it. I ended up just forking so I could keep working on my project, but it would be cool if we could get that sorted out from the official repo.
How would you compile and use an extension file with this library. For example, here is the one one from New York City: http://datamine.mta.info/sites/all/files/pdfs/nyct-subway.proto.txt
Given a feed that does NOT have an optional field (e.g. vehicle speed), the value returned when getting this value is 0
. So there's no way to differentiate "not included" from an actual value of zero.
const feed = realtime.transit_realtime.FeedMessage.decode(protobuf);
feed.entity.forEach((entity) => {
if (entity.vehicle) {
const speed = entity.vehicle.position.speed; // speed is 0
}
});
This may be similar to #52
Would be great to modify it so it could be used on the new Universal apps for Windows 10.
Seems the System.Serialization was removed so should it be as well from gtfs-realtime-bindings.
Currently each time the canonical gtfs-realtime.proto
changes, we need to go through a manual process for each language to update the bindings:
We should automate this process.
Some resources:
protobuf-maven-plugin
to automatically invoke protoc
as part of the build process - OneBusAway/onebusaway-gtfs-realtime-api#17Hi. I recently pushed out an R script to routinely produce the real-time protocol buffer for googlemaps. I have signed the CLA and read CONTRIBUTING.md and I would like to push a fork of my contributions.
What considerations should I take into account for my contribution?
This tool would be immensely valuable for mobile developers supporting iOS.
When working with the SEPTA GTFS-Rt feed, I found that the TripDescriptor hasScheduleRelationship() was returning false even for times when there were SCHEDULED schedule relationships present. SEPTA does not have any other statuses in their feed besides SCHEDULED, so that is all I was able to test. I'm unsure if this issue is present for other statuses.
I am getting error "unexpected end-group tag". I catch this error in an exception and then I loop the function back over to grab new data. I thought I could live this way , but it seems after a couple of hours or maybe even days, the program freezes. I am looking for a solution, but I am wondering if this has something to with the "unexpected end-group tag" or if i am just pulling two much. I am pulling data every 20 seconds now. I am running on a RPi 2B. Does any body have any ideas?
Error: invalid wire type 7 at offset 12 at BufferReader.Reader.skipType (/home/runner/node_modules/gtfs-realtime-bindings/node_modules/protobufjs/src/reader.js:375:19) at Function.decode (/home/runner/node_modules/gtfs-realtime-bindings/gtfs-realtime.js:148:28) at Request._callback (/home/runner/index.js:12:66) at Request.self.callback (/home/runner/node_modules/request/request.js:185:22) at Request.emit (events.js:198:13) at Request.EventEmitter.emit (domain.js:448:20) at Request. (/home/runner/node_modules/request/request.js:1161:10) at Request.emit (events.js:198:13) at Request.EventEmitter.emit (domain.js:448:20) at IncomingMessage. (/home/runner/node_modules/request/request.js:1083:12)
In the official Google Transit API Node.js sample the code on line 11 will throw this error: TypeError: Cannot read property 'decode' of undefined
.
// Incorrect
var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
// Corrected
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body);
We are using the GTFS Realtime bindings package for .NET to convert vehicle and trip update data in our database to the GTFS-RT ProtoBuf format. We do not have values for some of the optional elements such as vehicle bearing, occupancy, speed and vehicle stop status. But the C# object uses non-nullable properties for these and hence defaults values such as 0 for bearing, EMPTY for occupancy, 0 for speed, IN_TRANSIT_TO for vehicle stop status etc. The serialized ProtoBuf output also has these default values (instead of null). Would it be possible to update the code so that nulls are allowed for optional fields?
Right now we do not have unit tests for the dotnet bindings:
https://github.com/google/gtfs-realtime-bindings/tree/master/dotnet
This can potentially cause issues when we update the bindings if there have been changes in the toolchain - process for updating the bindings is described here:
https://github.com/google/gtfs-realtime-bindings/blob/master/dotnet/UPDATING.md
For comparison, we currently have unit tests for the Java bindings, and the code can be seen here:
https://github.com/google/gtfs-realtime-bindings/blob/master/java/src/test/java/com/google/transit/realtime/GtfsRealtimeTest.java
...which test the consumption of a sample bundled protobuf file included in this directory:
https://github.com/google/gtfs-realtime-bindings/tree/master/java/src/test/resources/com/google/transit/realtime
These tests are run as part of the process for updating the Java bindings, as described here:
https://github.com/google/gtfs-realtime-bindings/blob/master/java/UPDATING.md
We should implement similar unit tests in the .NET bindings so we can be confident we aren't breaking anything when we update the bindings.
Sample .NET code for consuming a protobuf file can be seen in the .NET README:
https://github.com/google/gtfs-realtime-bindings/blob/master/dotnet/README.md#example-code
I am using gradle, I have already put in my "build.gradle" the dependency:
compile group: 'io.mobilitydata.transit', name: 'gtfs-realtime-bindings', version: '0.0.4'
but when I try to compile the project it gives me this error.
Thank´s if anyone can help me.
Is anyone in the community using the Ruby bindings in this repository?
I'm hitting some issues regenerating them from the gtfs-realtime.proto, as it seems proto2 files aren't officially supported by Google's Ruby protobuf compiler, and the bindings generated by a 3rd party app don't match the ones currently in the repo. More at 3b2dd27.
I've posted the same question to the gtfs-realtime Google Group.
I am trying to add a header text to the allerts that I am generating programmatically using python in this way:
feedheader = feed.header
feedheader.gtfs_realtime_version = "2.0"
feedheader.timestamp = int(time.time())
feedheader.incrementality = 0
avvisi = getAvvisi()
for avviso in avvisi:
entity = feed.entity.add()
alert = entity.alert
entity.id = str(avviso["id"])
timerange = alert.active_period.add()
timerange.start = avviso["data"]
timerange.end = avviso["dataTerminePubblicazione"]
alert.cause = 1
alert.effect = 8
for linea in getLineeAvviso(avviso["id"]):
entityselector = alert.informed_entity.add()
entityselector.route_id = str(linea["id"])
entityselector.agency_id = linea["fk_linea"]
header = alert.header_text
header = "test"
For some reason the result does not contain the alert header. Am I doing something wrong?
This issue has already been described here
The reference gtfs-realtime.proto is now at v2, while the version in this repo is still at v1. (Correction - the value of gtfs_realtime_version
field in gtfs-realtime.proto doesn't need to change for GTFS-realtime v2.0 or any future version - see below comments in this thread).
I'm not sure if this requires that the bindings actually be regenerated (as no data structures changed) - if so, see bindings updating instructions at https://github.com/google/gtfs-realtime-bindings/blob/master/UPDATING.md.
An aside - should we remove gtfs-realtime.proto from this repo to avoid having two sources of truth?
More extreme options include moving these bindings into the google/transit repo where the spec lives, or using Git submodules.
It would be nice if this library also enforced the v2.0 semantics so things like FeedHeader.timestamp
were considered mandatory, and the Builder
would fail if this value wasn't provided for a v2.0 feed.
In the example Java code in this README, the import statements use io.mobilitydata.transit.realtime.GtfsRealtime
, but the actual path of the generated code is still com.google.transit.realtime.GtfsRealtime
.
Since the management of the gtfs-realtime-bindings has passed to @MobilityData, will this path be updated in the generated code in the future? Or kept to maintain backwards compatibility?
Either way a quick update to that README is needed.
Would like to see a PHP implementation. We use drupal @CDTA for out content management system. We have pieced our own version together but would like to see something is a bit more standardized.
When we first implemented our GTFS real time services, we rolled our own data model for our protobuf feed. We recently switched to using gtfs-realtime-bindings but we've run into an issue.
When we assign a zero value to Delay in Arrival (StopTimeEvent) for TripUpdates (i.e. the trip is on time) Google is interpreting it as no value and generating a warning report for our feed. A debug snapshot from Google shows:
stop_time_update {
stop_sequence: 1
arrival {
}
}
When what we're expecting to see is:
stop_time_update {
stop_sequence: 1
arrival {
delay: 0
}
}
The feed works correctly for any other delay values, just not for zero.
Do you have any information on how on-time trips are supposed to be notated with the gtfs-realtime-bindings model?
Hello,
I am using a get request to fetch the GTFS realtime data from NYC MTA. Please see the snippet of my code .....
let getData = (req, res, next) => { fetch(
http://datamine.mta.info/mta_esi.php?key=${MTA_API}&feed_id=${req.body.field_id}`)
.then(fetchRes => {
console.log(fetchRes.body);
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(fetchRes.body);
feed.entity.forEach(function(entity) {
if (entity.trip_update) {
console.log(entity.trip_update);
}
});
console.log(feed);
// return feed;
next();
}).then(jsonRes => {
res.locals.mta = jsonRes
next();
}).catch(err => {
console.log(err);
})
}`
i keep getting this error message:
TypeError: Cannot read property 'FeedMessage' of undefined
Any idea what might be wrong? I am trying to parse the GTFS data from MTA.
Is there any possible way how to convert GTFS VehiclePosition + GTFS Static to TripUpdate?
Want to calculate real time to arrival and create new feed.
If not using this library, maybe anybody here knows something to do that?
Hi folks,
I hope this finds you well. I hope I am blind or misunderstood the bindings version for node.js. I can get a decode example working but not for encoding. Here are the respective decoding and encoding source files. Can anyone open up my eyes please?
Decoding:
const GtfsRealtimeBindings = require('gtfs-realtime-bindings');
const debug = require('debug')('gtfs');
const fs = require("fs");
fs.open('./vehicle_position_another.pb', 'r', function(status, fd) {
if (status) {
debug('status: %s',status.message);
return;
}else{
// fs.readFile takes the file path and the callback
const buffer=fs.readFileSync('./vehicle_position_another.pb', (err, data) => {
// if there's an error, log it and return
if (err) {
debug('error: %s',err)
return
}
})
// Print the string representation of the data
if(buffer){
// decode
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(buffer);
if(feed){
debug('feed: %s',feed)
debug('feed.toString(): %s',feed.toString())
let header=feed.header;
if(header){
debug('header: %s',header)
let gtfsRealtimeVersion=header.gtfsRealtimeVersion;
if(gtfsRealtimeVersion){
debug('gtfsRealtimeVersion: %s',gtfsRealtimeVersion)
}
}
feed.entity.forEach(function(entity) {
if (entity.trip_update) {
debug('trip update')
}else if(entity.vehicle){
debug('vehicle position')
debug('entity to string: %s',entity.vehicle.toString())
}else if(entity.alert){
debug('alert')
}else{
debug('entity unknown')
}
});
// Verify the payload if necessary (i.e. when possibly incomplete or invalid)
let errMsg = GtfsRealtimeBindings.transit_realtime.FeedMessage.verify(feed);
if (errMsg){
debug('msg invalid')
throw Error(errMsg);
}else{
debug('msg valid')
}
feed.header.gtfsRealtimeVersion='2.0';
// Verify the payload if necessary (i.e. when possibly incomplete or invalid)
errMsg = GtfsRealtimeBindings.transit_realtime.FeedMessage.verify(feed);
if (errMsg){
debug('msg invalid')
throw Error(errMsg);
}else{
debug('msg valid')
}
const bufEnc = GtfsRealtimeBindings.transit_realtime.FeedMessage.encode(feed);
debug('bufEnc: %s',bufEnc)
debug('bufEnc.toString(): %s',bufEnc.toString())
}else{
debug('feed unavailabe')
}
}else{
debug('buffer unavailable')
}
}
});
Encoding:
const GtfsRealtimeBindings = require('gtfs-realtime-bindings');
const debug = require('debug')('gtfs');
let msgFeedHdr={
gtfs_realtime_version:"2.0"
}
var feedHeader = GtfsRealtimeBindings.transit_realtime.FeedHeader.create(msgFeedHdr); // or use .fromObject if conversion is necessary
debug('feedHeader created')
debug('feedHeader: %s',feedHeader)
var errMsg = GtfsRealtimeBindings.transit_realtime.FeedHeader.verify(feedHeader);
if (errMsg){
debug('feedHeader invalid')
throw Error(errMsg);
}else{
debug('feedHeader valid')
}
let msgFeedMsg={
header:{feedHeader}
}
var feedMessage = GtfsRealtimeBindings.transit_realtime.FeedMessage.create(msgFeedMsg); // or use .fromObject if conversion is necessary
debug('feedMessage created')
debug('feedMessage: %s',feedMessage)
var errMsg = GtfsRealtimeBindings.transit_realtime.FeedMessage.verify(feedMessage);
if (errMsg){
debug('feedMessage invalid')
throw Error(errMsg);
}else{
debug('feedMessage valid')
}
Decoding output:
~/Desktop/sandbox/gtfsRtBindingsDecode$ nodemon index.js
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
gtfs feed: [object Object] +0ms
gtfs feed.toString(): [object Object] +4ms
gtfs header: [object Object] +0ms
gtfs gtfsRealtimeVersion: 1.0 +0ms
gtfs vehicle position +0ms
gtfs entity to string: [object Object] +0ms
gtfs msg valid +1ms
gtfs msg valid +0ms
gtfs bufEnc: [object Object] +2ms
gtfs bufEnc.toString(): [object Object] +1ms
[nodemon] clean exit - waiting for changes before restart
Encoding output:
~/Desktop/sandbox/gtfsRtBindingsEncode$ nodemon index.js
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
gtfs feedHeader created +0ms
gtfs feedHeader: [object Object] +3ms
gtfs feedHeader valid +1ms
gtfs feedMessage created +0ms
gtfs feedMessage: [object Object] +0ms
gtfs feedMessage invalid +0ms
/home/user/Desktop/sandbox/gtfsRtBindingsEncode/index.js:31
throw Error(errMsg);
^
Error: header.gtfsRealtimeVersion: string expected
at Object.<anonymous> (/home/user/Desktop/sandbox/gtfsRtBindingsEncode/index.js:31:11)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
[nodemon] app crashed - waiting for file changes before starting...
Cheers!
Right now all unit tests parse a single GTFS-realtime VehiclePosition file.
We should add unit tests for all supported languages to parse TripUpdates and Alerts files too.
I understand this package is for node. I want to use this in my angular project, how do I proceed? Is there a way I can use it?
Installing via pip only gets 0.0.4. Please update!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.