Operation<T extends ProtoMessage, S extends ProtoMessage>.fromJson constructor

Operation<T extends ProtoMessage, S extends ProtoMessage>.fromJson(
  1. Object? j, [
  2. OperationHelper<T, S>? helper
])

Implementation

factory Operation.fromJson(Object? j, [OperationHelper<T, S>? helper]) {
  final json = j as Map<String, dynamic>;
  return Operation(
    name: json['name'] as String?,
    metadata: switch (json['metadata']) {
      null => null,
      Map<String, dynamic> metadata => Any.fromJson(metadata),
      _ => throw const FormatException('Invalid metadata'),
    },
    done: json['done'] as bool?,
    error: switch (json['error']) {
      null => null,
      Map<String, dynamic> status => Status.fromJson(status),
      _ => throw const FormatException('Invalid error'),
    },
    response: switch (json['response']) {
      null => null,
      Map<String, dynamic> response => Any.fromJson(response),
      _ => throw const FormatException('Invalid response'),
    },
    operationHelper: helper,
  );
}