You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
constfeed=realtime.transit_realtime.FeedMessage.decode(protobuf);feed.entity.forEach((entity)=>{if(entity.vehicle){constspeed=entity.vehicle.position.speed;// speed is 0}});
@nselikoff Thanks for the report! In Java bindings there is a hasSpeed() method that you can call to determine if the field has been set, but I'm not as familiar with the Node.js bindings. I'm assuming there isn't an equivalent?
@barbeau good question - just looked and there is not a similar method. However, I found a workaround using realtime.transit_realtime.Position.toObject:
constfeed=realtime.transit_realtime.FeedMessage.decode(protobuf);feed.entity.forEach((entity)=>{if(entity.vehicle){// using `toObject` only adds properties that exist in the protobufconstposition=realtime.transit_realtime.Position.toObject(entity.vehicle.position);// so speed will be undefined if not included in the protobufconstspeed=position.speed;// maybe you want it null// const speed = position.speed || null;}});
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.This may be similar to #52
The text was updated successfully, but these errors were encountered: