gistools/readers/gtfs/realtime/stop/
update.rs

1use alloc::string::String;
2use pbf::{BitCast, ProtoRead, Protobuf};
3
4use crate::readers::{GTFSRealtimeOccupancyStatus, GTFSRealtimeStopTimeEvent};
5
6/// The relation between the StopTimeEvents and the static schedule.
7#[repr(u8)]
8#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, BitCast)]
9pub enum GTFSRealtimeScheduleRelationshipUpdate {
10    /// The vehicle is proceeding in accordance with its static schedule of
11    /// stops, although not necessarily according to the times of the schedule.
12    /// At least one of arrival and departure must be provided. If the schedule
13    /// for this stop contains both arrival and departure times then so must
14    /// this update. Frequency-based trips (GTFS frequencies.txt with exact_times = 0)
15    /// should not have a SCHEDULED value and should use UNSCHEDULED instead.
16    #[default]
17    Scheduled = 0,
18    /// The stop is skipped, i.e., the vehicle will not stop at this stop.
19    /// Arrival and departure are optional.
20    Skipped = 1,
21    /// No StopTimeEvents are given for this stop.
22    /// The main intention for this value is to give time predictions only for
23    /// part of a trip, i.e., if the last update for a trip has a NO_DATA
24    /// specifier, then StopTimeEvents for the rest of the stops in the trip
25    /// are considered to be unspecified as well.
26    /// Neither arrival nor departure should be supplied.
27    NoData = 2,
28    /// The vehicle is operating a trip defined in GTFS frequencies.txt with exact_times = 0.
29    /// This value should not be used for trips that are not defined in GTFS frequencies.txt,
30    /// or trips in GTFS frequencies.txt with exact_times = 1. Trips containing StopTimeUpdates
31    /// with ScheduleRelationship=UNSCHEDULED must also set TripDescriptor.ScheduleRelationship=UNSCHEDULED.
32    /// NOTE: This field is still experimental, and subject to change. It may be
33    /// formally adopted in the future.
34    Unscheduled = 3,
35}
36
37/// Realtime update for arrival and/or departure events for a given stop on a
38/// trip. Updates can be supplied for both past and future events.
39/// The producer is allowed, although not required, to drop past events.
40///
41/// The update is linked to a specific stop either through stop_sequence or
42/// stop_id, so one of the fields below must necessarily be set.
43/// See the documentation in TripDescriptor for more information.
44#[derive(Debug, Default, Clone, PartialEq)]
45pub struct GTFSRealtimeStopTimeUpdate {
46    /// Must be the same as in stop_times.txt in the corresponding GTFS feed.
47    pub stop_sequence: Option<u32>, // 1 [uint32]
48    /// Realtime updates for arrival events.
49    pub arrival: Option<GTFSRealtimeStopTimeEvent>, // 2 [message]
50    /// Realtime updates for departure events.
51    pub departure: Option<GTFSRealtimeStopTimeEvent>, // 3 [message]
52    /// Must be the same as in stops.txt in the corresponding GTFS feed.
53    pub stop_id: Option<String>, // 4 [string]
54    /// The relation between the StopTimeEvents and the static schedule.
55    pub schedule_relationship: GTFSRealtimeScheduleRelationshipUpdate, // 5 [enum]
56    /// Realtime updates for certain properties defined within GTFS stop_times.txt
57    /// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
58    pub stop_time_properties: Option<GTFSRealtimeStopTimeProperties>, // 6 [message]
59    /// Expected occupancy after departure from the given stop.
60    /// Should be provided only for future stops.
61    /// In order to provide departure_occupancy_status without either arrival or
62    /// departure StopTimeEvents, ScheduleRelationship should be set to NO_DATA.
63    pub departure_occupancy_status: Option<GTFSRealtimeOccupancyStatus>, // 7 [enum]
64}
65/// Read in the contents of the GTFSRealtimeStopTimeUpdate
66impl ProtoRead for GTFSRealtimeStopTimeUpdate {
67    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
68        match tag {
69            1 => self.stop_sequence = Some(pb.read_varint()),
70            2 => {
71                let mut arrival = GTFSRealtimeStopTimeEvent::default();
72                pb.read_message(&mut arrival);
73                self.arrival = Some(arrival);
74            }
75            3 => {
76                let mut departure = GTFSRealtimeStopTimeEvent::default();
77                pb.read_message(&mut departure);
78                self.departure = Some(departure);
79            }
80            4 => self.stop_id = Some(pb.read_string()),
81            5 => self.schedule_relationship = pb.read_varint(),
82            6 => {
83                let mut stop_time_properties = GTFSRealtimeStopTimeProperties::default();
84                pb.read_message(&mut stop_time_properties);
85                self.stop_time_properties = Some(stop_time_properties);
86            }
87            7 => self.departure_occupancy_status = Some(pb.read_varint()),
88            _ => panic!("unknown tag {}", tag),
89        }
90    }
91}
92
93/// Provides the updated values for the stop time.
94/// NOTE: This message is still experimental, and subject to change. It may be formally adopted in the future.
95#[derive(Debug, Default, Clone, PartialEq)]
96pub struct GTFSRealtimeStopTimeProperties {
97    /// Supports real-time stop assignments. Refers to a stop_id defined in the GTFS stops.txt.
98    /// The new assigned_stop_id should not result in a significantly different trip experience for the end user than
99    /// the stop_id defined in GTFS stop_times.txt. In other words, the end user should not view this new stop_id as an
100    /// "unusual change" if the new stop was presented within an app without any additional context.
101    /// For example, this field is intended to be used for platform assignments by using a stop_id that belongs to the
102    /// same station as the stop originally defined in GTFS stop_times.txt.
103    /// To assign a stop without providing any real-time arrival or departure predictions, populate this field and set
104    /// StopTimeUpdate.schedule_relationship = NO_DATA.
105    /// If this field is populated, it is preferred to omit `StopTimeUpdate.stop_id` and use only `StopTimeUpdate.stop_sequence`. If
106    /// `StopTimeProperties.assigned_stop_id` and `StopTimeUpdate.stop_id` are populated, `StopTimeUpdate.stop_id` must match `assigned_stop_id`.
107    /// Platform assignments should be reflected in other GTFS-realtime fields as well
108    /// (e.g., `VehiclePosition.stop_id`).
109    /// NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
110    pub assigned_stop_id: Option<String>, // 1 [string]
111}
112/// Read in the contents of the GTFSRealtimeStopTimeProperties
113impl ProtoRead for GTFSRealtimeStopTimeProperties {
114    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
115        match tag {
116            1 => self.assigned_stop_id = Some(pb.read_string()),
117            _ => panic!("unknown tag {}", tag),
118        }
119    }
120}