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:
-
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). -
OffAir— Tiny single-key object{"offair":"..."}. Same rationale asOnAir. -
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. -
Nodes— Single-key object{"nodes":[...]}containing an array of node entries. Tried beforeStationsbecause node updates are more frequent than station updates in practice. -
Stations— Single-key object{"stations":[...]}containing an array of station entries. -
Unknown— If none of the above match, the raw JSON text is wrapped inUnknownfor diagnostic logging. This ensures forward compatibility with potential protocol extensions.