EventDto.fromJson constructor

EventDto.fromJson(
  1. Map<String, Object?> json
)

Implementation

factory EventDto.fromJson(Map<String, Object?> json) {
  final kind = json['kind'] as String;
  final seq = json['seq'] as int;
  final ts = json['tsMicros'] as int;
  final sessionId = json['sessionId'] as String;
  return switch (kind) {
    'heartbeat' =>
      HeartbeatEventDto(seq: seq, tsMicros: ts, sessionId: sessionId),
    'batch' => BatchEventDto(
        seq: seq,
        tsMicros: ts,
        sessionId: sessionId,
        entityUpdates: (json['entityUpdates'] as List? ?? const [])
            .map((e) => EntityUpdatedEventDto.fromMap(
                (e as Map).cast<String, Object?>()))
            .toList(),
        entityFirings: (json['entityFirings'] as List? ?? const [])
            .map((e) => EntityFiredEventDto.fromMap(
                (e as Map).cast<String, Object?>()))
            .toList(),
        systemFirings: (json['systemFirings'] as List? ?? const [])
            .map((e) => SystemFiredEventDto.fromMap(
                (e as Map).cast<String, Object?>()))
            .toList(),
        droppedFirings: json['droppedFirings'] as int? ?? 0,
      ),
    'log' => LogEmittedEventDto(
        seq: seq,
        tsMicros: ts,
        sessionId: sessionId,
        log: LogDto.fromJson((json['log'] as Map).cast<String, Object?>()),
      ),
    'topology' => TopologyEventDto.fromJsonInner(json,
        seq: seq, tsMicros: ts, sessionId: sessionId),
    _ => throw FormatException('Unknown event kind: $kind'),
  };
}