//! A host-side reader for the `.transit` (TRX2) packs [`crate::index`] writes. //! //! This is a **deliberate reimplementation** of the on-device reader //! `maps/src/main/rust/src/transit.rs`, not shared code. Two independent //! decoders of the same bytes must agree; keeping them separate is what makes a //! layout mistake in either one show up as a failing test or a dump diff instead //! of a pack the device silently mis-reads. Anything learned here must be //! mirrored there by hand — that is the point. //! //! Used by `index`'s tests and by `src/bin/transit_dump.rs`. use crate::index::{ HEADER_LEN, MAGIC, NONE, SECTION_COUNT, SECTION_COUNT_V6, VERSION, VERSION_MIN, }; // Section slot numbers. Slot `i` must describe section `i`; the device reader // hardcodes the same numbers. pub const SEC_STRINGS: usize = 0; pub const SEC_STOPS: usize = 1; pub const SEC_ROUTES: usize = 2; pub const SEC_ROUTE_STOPS: usize = 3; pub const SEC_ROUTE_TRIPS: usize = 4; pub const SEC_PROFILES: usize = 5; pub const SEC_PROFILES_IDX: usize = 6; pub const SEC_STOP_ROUTES: usize = 7; pub const SEC_STOP_ROUTES_IDX: usize = 8; pub const SEC_TRANSFERS: usize = 9; pub const SEC_TRANSFERS_IDX: usize = 10; pub const SEC_SERVICES: usize = 11; pub const SEC_EXCEPTIONS: usize = 12; pub const SEC_GRID_CELL_IDS: usize = 13; pub const SEC_GRID_CELL_OFF: usize = 14; pub const SEC_GRID_STOPS: usize = 15; pub const SEC_FEEDS: usize = 16; pub const SEC_FEED_TZ: usize = 17; pub const SEC_EXCEPTIONS_IDX: usize = 18; pub const SEC_STOP_ROUTE_POS: usize = 19; pub const SEC_SHAPE_COORDS: usize = 20; pub const SEC_ROUTE_SHAPE_IDX: usize = 21; pub const SEC_ROUTE_STOP_SHAPE: usize = 22; pub const SEC_FEED_MOTIS_PREFIX: usize = 23; pub const SEC_STOP_GTFS_ID: usize = 24; pub const SEC_ROUTE_TRIP_RECS: usize = 25; pub const SEC_ROUTE_TRIP_OFF: usize = 26; pub const SEC_RAIL_LINES: usize = 27; /// Bytes per v6 trip record: `u32 start_time, profile_id, service_idx, headsign_off`. pub const TRIP_REC_BYTES: usize = 16; pub use crate::reader_extra::read_uvarint; use crate::reader_extra::{ri32, ru32, ru64, zigzag}; /// One ROUTES entry (a 32-byte stride). #[derive(Clone, Copy, Debug)] pub struct RouteRec { pub name_off: u32, pub color: u32, pub route_type: u32, pub feed_idx: u32, pub n_stops: u32, pub first_route_stop: u32, pub n_trips: u32, /// Byte offset into ROUTE_TRIPS. pub trips_off: u32, } /// One trip decoded out of a route's ROUTE_TRIPS varint block. #[derive(Clone, Copy, Debug)] pub struct TripRec { pub start_time: u32, pub profile_id: u32, pub service_idx: u32, pub headsign_off: u32, } /// One SERVICES entry (a 12-byte stride). #[derive(Clone, Copy, Debug)] pub struct ServiceRec { /// Bit `b` set = runs on day `b`, Monday = 0. pub weekday_mask: u8, pub start_date: u32, pub end_date: u32, } /// The header's grid parameters. #[derive(Clone, Copy, Debug)] pub struct GridParams { pub lat0_e7: i32, pub lon0_e7: i32, pub cell_e7: u32, pub cols: u32, pub rows: u32, } pub struct Reader { buf: Vec, sec: Vec<(usize, usize)>, } include!("reader_s1.rs");