CockpitPerformanceMemoryReport.fromJson constructor

CockpitPerformanceMemoryReport.fromJson(
  1. Object? value
)

Implementation

factory CockpitPerformanceMemoryReport.fromJson(Object? value) {
  final json = _object(value, r'$.memory');
  final rawSamples = json['samples'];
  if (rawSamples is! List<Object?>) {
    throw const FormatException(r'$.memory.samples must be an array.');
  }
  final report = CockpitPerformanceMemoryReport(
    source: _string(json['source'], r'$.memory.source'),
    intervalMs: _positiveInt(json['intervalMs'], r'$.memory.intervalMs'),
    samples: rawSamples.map(CockpitPerformanceMemorySample.fromJson),
    droppedSamples: json['dropped'] == null
        ? 0
        : _nonNegativeInt(json['dropped'], r'$.memory.dropped'),
  );
  final encodedSummary = CockpitPerformanceMemorySummary.fromJson(
    json['summary'],
  );
  if (encodedSummary != report.summary) {
    throw const FormatException('Memory report summary is inconsistent.');
  }
  return report;
}