| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library protocol; | 5 library protocol; |
| 6 | 6 |
| 7 import 'dart:convert' show JsonDecoder; | 7 import 'dart:convert' show JsonDecoder; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Instances of the class [Request] represent a request that was received. | 10 * Instances of the class [Request] represent a request that was received. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 int toInt(Object value) { | 140 int toInt(Object value) { |
| 141 if (value is int) { | 141 if (value is int) { |
| 142 return value; | 142 return value; |
| 143 } else if (value is String) { | 143 } else if (value is String) { |
| 144 return int.parse(value, onError: (String value) { | 144 return int.parse(value, onError: (String value) { |
| 145 throw new RequestFailure(new Response.expectedInteger(this, value)); | 145 throw new RequestFailure(new Response.expectedInteger(this, value)); |
| 146 }); | 146 }); |
| 147 } | 147 } |
| 148 throw new RequestFailure(new Response.expectedInteger(this, value)); | 148 throw new RequestFailure(new Response.expectedInteger(this, value)); |
| 149 } | 149 } |
| 150 |
| 151 /** |
| 152 * Return a table representing the structure of the Json object that will be |
| 153 * sent to the client to represent this response. |
| 154 */ |
| 155 Map<String, Object> toJson() { |
| 156 Map jsonObject = new Map(); |
| 157 jsonObject[ID] = id; |
| 158 jsonObject[METHOD] = method; |
| 159 params.forEach((String key, Object value) { |
| 160 jsonObject[key] = value; |
| 161 }); |
| 162 return jsonObject; |
| 163 } |
| 150 } | 164 } |
| 151 | 165 |
| 152 /** | 166 /** |
| 153 * Instances of the class [Response] represent a response to a request. | 167 * Instances of the class [Response] represent a response to a request. |
| 154 */ | 168 */ |
| 155 class Response { | 169 class Response { |
| 156 /** | 170 /** |
| 157 * The name of the JSON attribute containing the id of the request for which | 171 * The name of the JSON attribute containing the id of the request for which |
| 158 * this is a response. | 172 * this is a response. |
| 159 */ | 173 */ |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 /** | 507 /** |
| 494 * The response to be returned as a result of the failure. | 508 * The response to be returned as a result of the failure. |
| 495 */ | 509 */ |
| 496 final Response response; | 510 final Response response; |
| 497 | 511 |
| 498 /** | 512 /** |
| 499 * Initialize a newly created exception to return the given reponse. | 513 * Initialize a newly created exception to return the given reponse. |
| 500 */ | 514 */ |
| 501 RequestFailure(this.response); | 515 RequestFailure(this.response); |
| 502 } | 516 } |
| OLD | NEW |