Request.fromJson constructor

Request.fromJson(
  1. Map<String, Object?> result
)

Return a request parsed from the given json, or null if the data is not a valid json representation of a request. The data is expected to have the following format:

{ 'clientRequestTime': millisecondsSinceEpoch 'id': String, 'method': methodName, 'params': { parameter_name: value } }

where both the parameters and clientRequestTime are optional.

The parameters can contain any number of name/value pairs. The clientRequestTime must be an int representing the time at which the client issued the request (milliseconds since epoch).

Implementation

factory Request.fromJson(Map<String, Object?> result) {
  var id = result[Request.ID];
  var method = result[Request.METHOD];
  if (id is! String || method is! String) {
    throw StateError('Unexpected type for id or method');
  }
  var time = result[Request.SERVER_REQUEST_TIME];
  if (time is! int?) {
    throw StateError('Unexpected type for server request time');
  }
  var params = result[Request.PARAMS];
  if (params is Map<String, Object?>?) {
    return Request(id, method, params, time);
  } else {
    throw StateError('Unexpected type for params');
  }
}