tryParseEventLine static method
Parses one trace line into TraceEventRecord when it contains a structured event emitted by event.
Returns null when the line is not an event line or is malformed.
Implementation
static TraceEventRecord? tryParseEventLine(String line) {
final parsedLine = _parseLine(line);
if (parsedLine == null) return null;
final message = parsedLine.message;
if (!message.startsWith(_eventMarker)) return null;
final jsonPayload = message.substring(_eventMarker.length);
final decoded = _decodeJsonObject(jsonPayload);
if (decoded == null) return null;
final version = decoded['v'];
if (version is! num || version.toInt() != _eventSchemaVersion) {
return null;
}
final type = decoded['type'];
if (type is! String || type.trim().isEmpty) return null;
final fields = <String, Object?>{};
for (final entry in decoded.entries) {
if (entry.key == 'v' || entry.key == 'type') continue;
fields[entry.key] = entry.value;
}
return TraceEventRecord(
timestampUs: parsedLine.timestampUs,
tag: parsedLine.tag,
type: type,
fields: fields,
);
}