I am trying to use https://github.com/dcodeIO/ProtoBuf.js to parse triments gtfs data.
Here is the code I have so far, it parses the .proto file correctly and creates the builder and has all the expected properties and methods, it throws an error when I try to decode any data with it.
Error: Data must be corrupt: Buffer overrun
the proto file is from https://developers.google.com/transit/gtfs-realtime/gtfs-realtime-proto
var ProtoBuf = require('protobufjs')
, request = require('request')
var transit = ProtoBuf.protoFromFile('gtfs-realtime.proto').build('transit_realtime')
request('http://developer.trimet.org/ws/V1/FeedSpecAlerts/?appID=618F30BB3062F39AF24AED9EC', parse)
function parse(err, res, body) {
try {
console.log(transit.FeedMessage.decode(res.body))
} catch(e) {
console.log(e)
}
}
Thanks to Brian Ferris I able to parse the first part of the header gtfs_realtime_version: "1"
but the parser fails on the next component (the time stamp uint64)
Thanks to
I'm not a node expert, but the root message type of a GTFS-realtime feed is "FeedMessage":
https://developers.google.com/transit/gtfs-realtime/reference
You seem to be trying to parse the feed as an "Alert" message:
console.log(transit.Alert.decode(res.body))
Maybe try changing Alert to FeedMessage and see what happens?