parse

Function parse 

Source
pub(crate) fn parse(data: &[u8]) -> Option<MonitorMessage>
Expand description

Attempts to parse a raw UDP datagram payload into a MonitorMessage.

Returns Some(message) on successful parse, or None if the data is not valid UTF-8 or not valid JSON (e.g., a stray/corrupt datagram).

§Parse order

The shapes are tried in a deliberate order to avoid ambiguous matches:

  1. OnAir — Tiny single-key object {"onair":"..."}. Tried first because it is the most common real-time event during active transmissions and is unambiguous (unique key name).

  2. OffAir — Tiny single-key object {"offair":"..."}. Same rationale as OnAir.

  3. Reflector — Two-key object {"reflector":"...","modules":[...]}. The key combination is unique, and this is only sent once per session, so false positives are not a concern.

  4. Nodes — Single-key object {"nodes":[...]} containing an array of node entries. Tried before Stations because node updates are more frequent than station updates in practice.

  5. Stations — Single-key object {"stations":[...]} containing an array of station entries.

  6. Unknown — If none of the above match, the raw JSON text is wrapped in Unknown for diagnostic logging. This ensures forward compatibility with potential protocol extensions.