Chromium Code Reviews| Index: pkg/analysis_server/lib/src/protocol.dart |
| diff --git a/pkg/analysis_server/lib/src/protocol.dart b/pkg/analysis_server/lib/src/protocol.dart |
| index 8cee0f6d5b0f8160ec5e7a8da587b47cba342e76..cb620b937e57f78c6fc930de25638d5855b750f7 100644 |
| --- a/pkg/analysis_server/lib/src/protocol.dart |
| +++ b/pkg/analysis_server/lib/src/protocol.dart |
| @@ -534,30 +534,53 @@ class Request { |
| factory Request.fromString(String data) { |
| try { |
| var result = JSON.decode(data); |
| - if (result is! Map) { |
| - return null; |
| - } |
| - var id = result[Request.ID]; |
| - var method = result[Request.METHOD]; |
| - if (id is! String || method is! String) { |
| - return null; |
| - } |
| - var time = result[Request.CLIENT_REQUEST_TIME]; |
| - if (time != null && time is! int) { |
| - return null; |
| - } |
| - var params = result[Request.PARAMS]; |
| - if (params is Map || params == null) { |
| - return new Request(id, method, params, time); |
| - } else { |
| - return null; |
| - } |
| + return new Request.fromJson(result); |
| } catch (exception) { |
| return null; |
| } |
| } |
| /** |
| + * 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: |
| + * |
| + * { |
| + * 'id': String, |
| + * 'method': methodName, |
| + * 'params': { |
| + * paramter_name: value |
| + * } |
| + * 'clientRequestTime': millisecondsSinceEpoch |
|
Brian Wilkerson
2015/06/15 15:41:40
nit: It would look nicer if this line were moved b
danrubel
2015/06/15 16:25:17
Done.
|
| + * } |
| + * |
| + * 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). |
| + */ |
| + factory Request.fromJson(result) { |
|
Brian Wilkerson
2015/06/15 15:41:40
Parameters should have type annotations. Can we mo
danrubel
2015/06/15 16:25:18
Done.
|
| + if (result is! Map) { |
| + return null; |
| + } |
| + var id = result[Request.ID]; |
| + var method = result[Request.METHOD]; |
| + if (id is! String || method is! String) { |
| + return null; |
| + } |
| + var time = result[Request.CLIENT_REQUEST_TIME]; |
| + if (time != null && time is! int) { |
| + return null; |
| + } |
| + var params = result[Request.PARAMS]; |
| + if (params is Map || params == null) { |
| + return new Request(id, method, params, time); |
| + } else { |
| + return null; |
| + } |
| + } |
| + |
| + /** |
| * Return a table representing the structure of the Json object that will be |
| * sent to the client to represent this response. |
| */ |