Runtime (Rust): expand ResultFormatter to full TS parity (24 new methods)#5
Runtime (Rust): expand ResultFormatter to full TS parity (24 new methods)#5kevinelliott wants to merge 1 commit into
Conversation
…ods) Mirrors the C runtime expansion (PR #4) into ads_runtime::ResultFormatter, with every type/code/label/value string cross-checked against the production TS reference (runtimes/typescript/utils/result_formatter.ts) this time — which surfaced several wrong codes in both the original Rust formatters AND the C PR: Corrections to EXISTING methods (TS-verified): - position: code ARP → POS; direction uses strictly > 0 (TS: 0 → S/W) - timestamp: kind/code/label "timestamp"/TS/"Timestamp" → "time"/TIMESTAMP/"Message Timestamp"; value now timestampToString (HH:MM:SS / ISO) not raw int - callsign: code CS → CALLSIGN - flight_number: code FLT → FLIGHT; no-ops on empty string (TS guard `if (fields[3])`) - tail: label "Tail Number" → "Tail" - departure_airport: kind/code "airport_origin"/DEP → "icao"/ORG - arrival_airport: kind/code "airport_destination"/ARR → "icao"/DST - heading: value drops the ° suffix (TS emits plain number) - fuel: now an alias of current_fuel (fuel_on_board/FOB/ "Fuel On Board") — TS has no plain `fuel` New methods: Time-of-day family (timestampToString display): eta, out, off, on, r#in Calendar: day (MSG_DAY), month (MSG_MON), departure_day, arrival_day Velocity/atmosphere: mach ("{} mach"), groundspeed (GSPD), airspeed (ASPD/"True Airspeed"), temperature(&str, M→-/P→+), total_air_temp(&str) Fuel: current_fuel (FOB), remaining_fuel (' FUEL_REM' — leading space preserved from TS for byte parity) Routing: alternate_airport (ALT_DST), arrival_runway (ARWY), alternate_runway (ALT_ARWY) Events: state_change, door_event Text: text, unknown_sep, unknown_arr_sep Diagnostics: checksum (0x%04x tail-4 format), checksum_algorithm (raw only — the TS item push is commented out; mirrored exactly) Generic: push_item + pub timestamp_to_string timestamp_to_string implements TS DateTimeUtils.timestampToString's three-tier logic (HH:MM:SS / "YYYY-MM-DDTHH:MM:SS" masked / full ISO) via a chrono-free civil-from-days conversion. Known divergence (documented inline): state_change emits raw from/to codes; TS routes them through RouteUtils.formatFlightState which has no Rust port yet. Corpus reconciliation will flag affected samples. NOTE for PR #4 (C formatters): the C branch has the pre-verification code values (ARP, MSG_MONTH, ALT_RWY, GS, IAS, CKSUM…). Will fix on that branch to match before it merges. Verified: cargo build clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Rust ChangesResultFormatter API Expansion
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Cross-checking against the production TS reference (runtimes/typescript/utils/result_formatter.ts) while writing the Rust mirror (PR #5) surfaced several wrong type/code/label strings in this branch's original commit. Corrected to exact TS values: Existing formatters: - position: code ARP → POS; direction strictly > 0 → N/E (TS: 0 → S/W) - timestamp: timestamp/TS/"Timestamp" + numeric → time/TIMESTAMP/"Message Timestamp" + timestampToString display (moved after push_tod) - callsign: CS → CALLSIGN - flight_number: FLT → FLIGHT; no-ops on empty (TS guard) - tail: "Tail Number" → "Tail" - departure_airport: airport_origin/DEP → icao/ORG - arrival_airport: airport_destination/ARR → icao/DST - heading: drops "deg" unit (TS emits plain number) - fuel: fuel/FUEL/"Fuel" → fuel_on_board/FOB/ "Fuel On Board" (alias of currentFuel; TS has no plain fuel) New formatters from the earlier commit: - month: MSG_MONTH/"Month" → MSG_MON/"Month of Year" - mach: "Mach" → "Mach Number" + "{} mach" unit - groundspeed: groundspeed/GS/"Ground Speed" → aircraft_groundspeed/GSPD/"Aircraft Groundspeed" - airspeed: IAS/"Indicated Airspeed" → ASPD/"True Airspeed" - temperature/total_air_temp: signature now (r, const char *) with M→- / P→+ conversion + empty no-op (TS takes a string); total_air_temp item type is 'temperature' (TS quirk) - remaining_fuel: " FUEL_REM" leading space preserved (TS quirk) - alternate_runway: ALT_RWY → ALT_ARWY - in/out labels: "Arrival at Gate"/"Departure from Gate" → "In Gate Time"/"Out of Gate Time" - checksum: checksum/CKSUM/"Checksum"/%llx → message_checksum/CHECKSUM/"Message Checksum"/ 0x + zero-padded last-4 lowercase hex - checksum_algorithm: item push REMOVED — TS stores the raw field only (its item block is commented out) ads_fmt_time_of_day_str now implements TS timestampToString's full three-tier logic (HH:MM:SS / "YYYY-MM-DD'T'HH:MM:SS" masked / full ISO) via chrono-free civil-from-days. Matches the Rust runtime expansion in PR #5 exactly; both runtimes now emit byte-identical items per the TS reference. Verified: runtimes/c builds clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c1bf5e5e0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Self::push(result, "icao", "ALT_DST", "Alternate Destination", s); | ||
| } | ||
|
|
||
| pub fn arrival_runway(result: &mut DecodeResult, value: impl Into<Option<JsonValue>>) { |
There was a problem hiding this comment.
Add the missing departure runway formatter
This runway formatter block adds arrival_runway and alternate_runway, but still omits the TS departureRunway counterpart (runway/DEPRWY/Departure Runway) even though the corpus contains DEPRWY/departure_runway outputs in arinc_702 samples. Any Rust hatch or future codegen path that needs parity for departure runway must either duplicate raw insertion plus item pushing or cannot call the parity API, so add departure_runway alongside these methods.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
runtimes/rust/src/result_formatter.rs (1)
374-382: 💤 Low valueConsider accepting a slice instead of
Vec<String>by value.Taking
Vec<String>by value consumes the vector, forcing callers to give up ownership. Accepting&[String]or&[impl AsRef<str>]would allow callers to retain ownership and avoid unnecessary allocation when they already have a slice or borrowed data.Suggested signature change
- pub fn unknown_arr_sep(result: &mut DecodeResult, values: Vec<String>, sep: &str) { + pub fn unknown_arr_sep(result: &mut DecodeResult, values: &[String], sep: &str) { if values.is_empty() { return; } let joined = values.join(sep); Self::unknown_sep(result, &joined, sep); }Then update
unknown_arrto pass a reference:pub fn unknown_arr(result: &mut DecodeResult, values: Vec<String>) { - Self::unknown_arr_sep(result, values, ","); + Self::unknown_arr_sep(result, &values, ","); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@runtimes/rust/src/result_formatter.rs` around lines 374 - 382, Change unknown_arr and unknown_arr_sep to accept a slice (e.g., &[String] or, better, &[impl AsRef<str>]) instead of consuming Vec<String> so callers don't lose ownership; update the signatures of unknown_arr(result: &mut DecodeResult, values: &[String]) and unknown_arr_sep(result: &mut DecodeResult, values: &[String], sep: &str) (or use a generic AsRef-based slice) and change the implementation to return early on values.is_empty(), join via values.join(sep) or map AsRef::as_ref, and call Self::unknown_sep(result, &joined, sep); then update all call sites that currently pass a Vec<String> to pass a slice (.as_slice() or &vec) so ownership is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@runtimes/rust/src/result_formatter.rs`:
- Around line 374-382: Change unknown_arr and unknown_arr_sep to accept a slice
(e.g., &[String] or, better, &[impl AsRef<str>]) instead of consuming
Vec<String> so callers don't lose ownership; update the signatures of
unknown_arr(result: &mut DecodeResult, values: &[String]) and
unknown_arr_sep(result: &mut DecodeResult, values: &[String], sep: &str) (or use
a generic AsRef-based slice) and change the implementation to return early on
values.is_empty(), join via values.join(sep) or map AsRef::as_ref, and call
Self::unknown_sep(result, &joined, sep); then update all call sites that
currently pass a Vec<String> to pass a slice (.as_slice() or &vec) so ownership
is preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 03f5e1c3-dfc2-4b0c-b83f-bf57556e439e
📒 Files selected for processing (1)
runtimes/rust/src/result_formatter.rs
Summary
Mirrors the C runtime expansion (#4) into
ads_runtime::ResultFormatter— but this time with everytype/code/label/valuestring cross-checked against the production TS reference (runtimes/typescript/utils/result_formatter.ts). That verification surfaced several wrong codes in both the original Rust formatters and PR #4's C versions.Corrections to existing methods (TS-verified)
positionARP;>= 0→ N/EPOS; strictly> 0→ N/E (TS: 0 → S/W)timestamptimestamp/TS/"Timestamp", raw int valuetime/TIMESTAMP/"Message Timestamp",timestampToStringcallsignCSCALLSIGNflight_numberFLTFLIGHT; no-ops on empty stringtaildeparture_airportairport_origin/DEPicao/ORGarrival_airportairport_destination/ARRicao/DSTheading°suffixfuelfuel/FUELcurrent_fuel(fuel_on_board/FOB)New methods (24)
timestampToStringdisplay):eta,out,off,on,r#inday(MSG_DAY),month(MSG_MON),departure_day,arrival_daymach("{} mach"),groundspeed(GSPD),airspeed(ASPD/"True Airspeed"),temperature(&str)with M→-/P→+ conversion,total_air_temp(&str)current_fuel(FOB),remaining_fuel(' FUEL_REM'— leading space preserved from TS for byte parity)alternate_airport(ALT_DST),arrival_runway(ARWY),alternate_runway(ALT_ARWY)state_change,door_eventtext,unknown_sep,unknown_arr_sepchecksum(TS0x+ tail-4 hex format),checksum_algorithm(raw only — the TS item push is commented out; mirrored exactly)push_item, pubtimestamp_to_stringtimestamp_to_stringimplements TSDateTimeUtils.timestampToString's three-tier logic (HH:MM:SS / "YYYY-MM-DDTHH:MM:SS" masked / full ISO) via a chrono-free civil-from-days conversion — no new dependencies.Known divergence (documented inline)
state_changeemits raw from/to codes; TS routes them throughRouteUtils.formatFlightState, which has no Rust port yet. Corpus reconciliation will flag affected samples.Follow-up required on PR #4
The C branch (
feat/c-runtime-formatters) carries the pre-verification code values (ARP,MSG_MONTH,ALT_RWY,GS,IAS,CKSUM, missing' FUEL_REM'space, item-pushingchecksum_algorithm). Those need the same corrections before #4 merges — will push fixes to that branch.What this unblocks
todo!()hatch stubs lose their biggest blocker (missing formatter methods)acars-decoder-rust's_shared.rsshim (~25 duplicated helpers) can be deleted in favor of the runtime once the submodule bumpsTest plan
cargo buildclean inruntimes/rustacars-decoder-rust, delete_shared.rs, re-point hatches atResultFormatter🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
New Features