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

1#![cfg_attr(feature = "nightly", coverage(off))]
2// NOTE: THis is an experimental module, exists incase the GTFS-Realtime spec changes to include it
3
4mod time_event;
5mod update;
6
7use crate::readers::GTFSRealtimeTranslatedString;
8use alloc::string::String;
9use pbf::{BitCast, ProtoRead, Protobuf};
10pub use time_event::*;
11pub use update::*;
12
13/// The type of wheelchair boarding accessibility at a stop.
14#[repr(u8)]
15#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, BitCast)]
16pub enum GTFSRealtimeWheelchairBoarding {
17    /// Unknown accessibility.
18    #[default]
19    Unknown = 0,
20    /// Wheelchair boarding is available.
21    Available = 1,
22    /// Wheelchair boarding is not available.
23    NotAvailable = 2,
24}
25
26/// Describes a stop which is served by trips. All fields are as described in the GTFS-Static specification.
27/// NOTE: This message is still experimental, and subject to change. It may be formally adopted in the future.
28#[derive(Debug, Default, Clone, PartialEq)]
29pub struct GTFSRealtimeStop {
30    /// The stop_id of the stop
31    pub stop_id: Option<String>, // 1 [string]
32    /// The stop_code of the stop
33    pub stop_code: Option<GTFSRealtimeTranslatedString>, // 2 [message]
34    /// The stop_name of the stop
35    pub stop_name: Option<GTFSRealtimeTranslatedString>, // 3 [message]
36    /// The tts_stop_name of the stop
37    pub tts_stop_name: Option<GTFSRealtimeTranslatedString>, // 4 [message]
38    /// The stop_desc of the stop
39    pub stop_desc: Option<GTFSRealtimeTranslatedString>, // 5 [message]
40    /// The lat of the stop
41    pub stop_lat: Option<f32>, // 6 [float]
42    /// The lon of the stop
43    pub stop_lon: Option<f32>, // 7 [float]
44    /// The zone_id of the stop
45    pub zone_id: Option<String>, // 8 [string]
46    /// The stop_url of the stop
47    pub stop_url: Option<GTFSRealtimeTranslatedString>, // 9 [string]
48    /// The parent_station of the stop
49    pub parent_station: Option<String>, // 11 [string]
50    /// The stop_timezone of the stop
51    pub stop_timezone: Option<String>, // 12 [string]
52    /// The wheelchair_boarding of the stop
53    pub wheelchair_boarding: Option<GTFSRealtimeWheelchairBoarding>, // 13 [enum]
54    /// The level_id of the stop
55    pub level_id: Option<String>, // 14 [string]
56    /// The platform_code of the stop
57    pub platform_code: Option<GTFSRealtimeTranslatedString>, // 15 [string]
58}
59/// Read in the contents of the blob header
60impl ProtoRead for GTFSRealtimeStop {
61    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
62        match tag {
63            1 => self.stop_id = Some(pb.read_string()),
64            2 => {
65                self.stop_code = {
66                    let mut stop_code = GTFSRealtimeTranslatedString::default();
67                    pb.read_message(&mut stop_code);
68                    Some(stop_code)
69                }
70            }
71            3 => {
72                self.stop_name = {
73                    let mut stop_name = GTFSRealtimeTranslatedString::default();
74                    pb.read_message(&mut stop_name);
75                    Some(stop_name)
76                }
77            }
78            4 => {
79                self.tts_stop_name = {
80                    let mut tts_stop_name = GTFSRealtimeTranslatedString::default();
81                    pb.read_message(&mut tts_stop_name);
82                    Some(tts_stop_name)
83                }
84            }
85            5 => {
86                self.stop_desc = {
87                    let mut stop_desc = GTFSRealtimeTranslatedString::default();
88                    pb.read_message(&mut stop_desc);
89                    Some(stop_desc)
90                }
91            }
92            6 => self.stop_lat = Some(pb.read_fixed()),
93            7 => self.stop_lon = Some(pb.read_fixed()),
94            8 => self.zone_id = Some(pb.read_string()),
95            9 => {
96                self.stop_url = {
97                    let mut stop_url = GTFSRealtimeTranslatedString::default();
98                    pb.read_message(&mut stop_url);
99                    Some(stop_url)
100                }
101            }
102            11 => self.parent_station = Some(pb.read_string()),
103            12 => self.stop_timezone = Some(pb.read_string()),
104            13 => self.wheelchair_boarding = Some(pb.read_varint()),
105            14 => self.level_id = Some(pb.read_string()),
106            15 => {
107                self.platform_code = {
108                    let mut platform_code = GTFSRealtimeTranslatedString::default();
109                    pb.read_message(&mut platform_code);
110                    Some(platform_code)
111                }
112            }
113            _ => panic!("unknown tag {}", tag),
114        }
115    }
116}