Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: pkg/analysis_server/lib/src/protocol.dart

Issue 1181363004: refactor Reqest.fromJson for use by performance measurement tests (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8a15ebe9e9418a6863555ef60c323afff56e7e8f 100644
--- a/pkg/analysis_server/lib/src/protocol.dart
+++ b/pkg/analysis_server/lib/src/protocol.dart
@@ -518,12 +518,12 @@ class Request {
* have the following format:
*
* {
+ * 'clientRequestTime': millisecondsSinceEpoch
* 'id': String,
* 'method': methodName,
* 'params': {
* paramter_name: value
* }
- * 'clientRequestTime': millisecondsSinceEpoch
* }
*
* where both the parameters and clientRequestTime are optional.
@@ -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;
+ if (result is Map) {
+ return new Request.fromJson(result);
}
+ return null;
} 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:
+ *
+ * {
+ * 'clientRequestTime': millisecondsSinceEpoch
+ * 'id': String,
+ * 'method': methodName,
+ * 'params': {
+ * paramter_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).
+ */
+ factory Request.fromJson(Map<String, dynamic> result) {
+ 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.
*/
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698