gistools/readers/gtfs/realtime/stop/time_event.rs
1use pbf::{ProtoRead, Protobuf};
2
3/// Timing information for a single predicted event (either arrival or
4/// departure).
5///
6/// Timing consists of delay and/or estimated time, and uncertainty.
7/// - delay should be used when the prediction is given relative to some
8/// existing schedule in GTFS.
9/// - time should be given whether there is a predicted schedule or not. If
10/// both time and delay are specified, time will take precedence
11/// (although normally, time, if given for a scheduled trip, should be
12/// equal to scheduled time in GTFS + delay).
13///
14/// Uncertainty applies equally to both time and delay.
15/// The uncertainty roughly specifies the expected error in true delay (but
16/// note, we don't yet define its precise statistical meaning). It's possible
17/// for the uncertainty to be 0, for example for trains that are driven under
18/// computer timing control.
19#[derive(Debug, Default, Clone, PartialEq)]
20pub struct GTFSRealtimeStopTimeEvent {
21 /// Delay (in seconds) can be positive (meaning that the vehicle is late) or
22 /// negative (meaning that the vehicle is ahead of schedule). Delay of 0
23 /// means that the vehicle is exactly on time.
24 pub delay: Option<i32>, // 1 [int32]
25 /// Event as absolute time.
26 /// In Unix time (i.e., number of seconds since January 1st 1970 00:00:00 UTC).
27 pub time: Option<i64>, // 2 [int64]
28 /// If uncertainty is omitted, it is interpreted as unknown.
29 /// If the prediction is unknown or too uncertain, the delay (or time) field
30 /// should be empty. In such case, the uncertainty field is ignored.
31 /// To specify a completely certain prediction, set its uncertainty to 0.
32 pub uncertainty: Option<i32>, // 3 [int32]
33}
34/// Read in the contents of the blob header
35impl ProtoRead for GTFSRealtimeStopTimeEvent {
36 fn read(&mut self, tag: u64, pb: &mut Protobuf) {
37 match tag {
38 1 => self.delay = Some(pb.read_s_varint()),
39 2 => self.time = Some(pb.read_s_varint()),
40 3 => self.uncertainty = Some(pb.read_s_varint()),
41 _ => panic!("unknown tag {}", tag),
42 }
43 }
44}