using System; using GeoVLog.Core.Hdf5; namespace GeoVLog.Core.Parsers { /// /// Routes raw sensor message bytes to the appropriate parser based on sensor schema. /// Provides a unified interface to parse any sensor message to a strongly-typed object. /// internal static class ParserRouter { /// /// Parse a raw sensor message according to the specified sensor schema. /// /// The schema/type of sensor data (determines parsing logic). /// The raw message bytes from the sensor. /// /// Timestamp associated with the message (UTC). This may be used in parsing (e.g., to construct full date/time). /// /// /// A parsed object representing the sensor data (for example, a GpsReading for GPS data), /// or if parsing failed or is not implemented for the schema. /// public static object? Parse(SensorSchema schema, ReadOnlySpan msg, DateTime timestamp) { try { // Select parser based on sensor schema switch (schema) { case SensorSchema.Gps: if (GpsParser.TryParse(msg, timestamp, out var gps)) return gps; break; case SensorSchema.Imu: if (ImuParser.TryParse(msg, timestamp, out var imu)) return imu; break; case SensorSchema.Mag: if (MagParser.TryParse(msg, timestamp, out var mag)) return mag; break; case SensorSchema.Vlf: if (VlfParser.TryParse(msg, timestamp, out var vlf)) return vlf; break; case SensorSchema.RadarAlt: if (RadarAltParser.TryParse(msg, timestamp, out var ra)) return ra; break; default: break; } } catch (Exception ex) { // Log or handle parse exception as needed (in production, possibly log an error) // Return null to indicate parsing failure System.Diagnostics.Debug.WriteLine($"Parse error for schema {schema}: {ex}"); } return null; } } }