Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions runtimes/c/include/ads_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ uint32_t ads_bitslice(uint32_t byte, uint8_t bit_start, uint8_t bit_end);
uint32_t ads_concat_bits(const uint32_t *values, size_t count);

/* ─── Formatter helpers (push items onto result.formatted.items) ──────── */
/* Every ads_fmt_* takes ownership of the ads_value_t pointers passed in and
* frees them (matches ads_result_raw_set's transfer semantics). Pass NULL
* to no-op (matches the TS pattern of guarding before calling). */
Comment on lines +63 to +65

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Documentation overstates ownership scope.

The comment says "Every ads_fmt_*" takes ownership of ads_value_t*, but several ads_fmt_* functions declared below don't accept ads_value_t* at all (e.g., ads_fmt_state_change, ads_fmt_door_event, ads_fmt_text, ads_fmt_unknown*, ads_fmt_checksum_algorithm, ads_fmt_push_item). Consider clarifying:

📝 Suggested wording
-/* Every ads_fmt_* takes ownership of the ads_value_t pointers passed in and
+/* Each ads_fmt_* that accepts an ads_value_t* takes ownership of it and
  * frees them (matches ads_result_raw_set's transfer semantics). Pass NULL
  * to no-op (matches the TS pattern of guarding before calling). */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/* Every ads_fmt_* takes ownership of the ads_value_t pointers passed in and
* frees them (matches ads_result_raw_set's transfer semantics). Pass NULL
* to no-op (matches the TS pattern of guarding before calling). */
/* Each ads_fmt_* that accepts an ads_value_t* takes ownership of it and
* frees them (matches ads_result_raw_set's transfer semantics). Pass NULL
* to no-op (matches the TS pattern of guarding before calling). */
🤖 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/c/include/ads_helpers.h` around lines 63 - 65, The header comment
incorrectly states "Every ads_fmt_* takes ownership of the ads_value_t
pointers", which overstates ownership because several functions in this file
(e.g., ads_fmt_state_change, ads_fmt_door_event, ads_fmt_text, ads_fmt_unknown*,
ads_fmt_checksum_algorithm, ads_fmt_push_item) do not accept ads_value_t* and
thus do not take ownership; update the comment in
runtimes/c/include/ads_helpers.h to explicitly state that only the ads_fmt_*
variants that accept ads_value_t* parameters transfer ownership and free them
(and that callers should pass NULL to no-op), and optionally list or reference
the specific functions that do not take ads_value_t* to avoid confusion.


void ads_fmt_position(ads_decode_result_t *r, ads_value_t *lat, ads_value_t *lon);
void ads_fmt_position_value(ads_decode_result_t *r, ads_value_t *position);
Expand All @@ -75,6 +78,71 @@ void ads_fmt_arrival_airport(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_fuel(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_unknown_arr(ads_decode_result_t *r, const char *const *values, size_t count);

/* Time-of-day formatters (value in seconds since midnight). */
void ads_fmt_eta(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_off(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_on(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_in(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_out(ads_decode_result_t *r, ads_value_t *v);

/* Calendar formatters. */
void ads_fmt_day(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_departure_day(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_arrival_day(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_month(ads_decode_result_t *r, ads_value_t *v);

/* Velocity / atmosphere formatters. */
void ads_fmt_mach(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_groundspeed(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_airspeed(ads_decode_result_t *r, ads_value_t *v);
/* TS signature: takes the raw STRING and converts M→- / P→+ before
* numeric parse; no-ops on empty input. */
void ads_fmt_temperature(ads_decode_result_t *r, const char *value);
void ads_fmt_total_air_temp(ads_decode_result_t *r, const char *value);

/* Fuel formatters. */
void ads_fmt_current_fuel(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_remaining_fuel(ads_decode_result_t *r, ads_value_t *v);

/* Routing formatters. */
void ads_fmt_alternate_airport(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_arrival_runway(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_alternate_runway(ads_decode_result_t *r, ads_value_t *v);

/* Event formatters. */
void ads_fmt_state_change(ads_decode_result_t *r, const char *from, const char *to);
void ads_fmt_door_event(ads_decode_result_t *r, const char *door, const char *state);

/* Free-text formatters. */
void ads_fmt_text(ads_decode_result_t *r, const char *value);
void ads_fmt_unknown(ads_decode_result_t *r, const char *value);
void ads_fmt_unknown_sep(ads_decode_result_t *r, const char *value, const char *sep);
void ads_fmt_unknown_arr_sep(ads_decode_result_t *r, const char *const *values, size_t count, const char *sep);

/* Diagnostic formatters. */
void ads_fmt_checksum(ads_decode_result_t *r, ads_value_t *v);
void ads_fmt_checksum_algorithm(ads_decode_result_t *r, const char *value);

/* Generic structured-item push for plugins that emit custom item shapes
* (OHMA, WRN, SQ, ATIS, etc.). Stores no raw field; just pushes the item. */
void ads_fmt_push_item(ads_decode_result_t *r, const char *type, const char *code,
const char *label, const char *value);

/* Time-of-day helper: seconds since midnight → "HH:MM:SS" (for < 86400);
* larger values stringify as-is. Caller frees the returned malloc'd string. */
char *ads_fmt_time_of_day_str(int64_t seconds);

/* ─── Result mutators ────────────────────────────────────────────────────── */
/* For escape hatches that need to override fields the ads_result_new() call
* already set up (e.g. variant-dependent description, custom remaining text). */

void ads_result_set_description(ads_decode_result_t *r, const char *description);
void ads_result_set_remaining(ads_decode_result_t *r, const char *text);
void ads_result_append_remaining(ads_decode_result_t *r, const char *text, const char *sep);
const char *ads_result_get_remaining(const ads_decode_result_t *r);
void ads_result_set_decode_level(ads_decode_result_t *r, ads_decode_level_t level);
void ads_result_clear_items(ads_decode_result_t *r);

#ifdef __cplusplus
}
#endif
Expand Down
Loading
Loading