| 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 * An abstract enumeration. | 10 * An abstract enumeration. |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 /** | 455 /** |
| 456 * Initialize a newly created instance to represent an error condition caused | 456 * Initialize a newly created instance to represent an error condition caused |
| 457 * by a [request] that cannot be handled by any known handlers. | 457 * by a [request] that cannot be handled by any known handlers. |
| 458 */ | 458 */ |
| 459 Response.unknownRequest(Request request) | 459 Response.unknownRequest(Request request) |
| 460 : this(request.id, new RequestError(-7, 'Unknown request')); | 460 : this(request.id, new RequestError(-7, 'Unknown request')); |
| 461 | 461 |
| 462 Response.contextAlreadyExists(Request request) | 462 Response.contextAlreadyExists(Request request) |
| 463 : this(request.id, new RequestError(-8, 'Context already exists')); | 463 : this(request.id, new RequestError(-8, 'Context already exists')); |
| 464 | 464 |
| 465 Response.unsupportedFeature(Request request, String message) |
| 466 : this(request.id, new RequestError(-9, message)); |
| 467 |
| 465 /** | 468 /** |
| 466 * Initialize a newly created instance based upon the given JSON data | 469 * Initialize a newly created instance based upon the given JSON data |
| 467 */ | 470 */ |
| 468 factory Response.fromJson(Map<String, Object> json) { | 471 factory Response.fromJson(Map<String, Object> json) { |
| 469 try { | 472 try { |
| 470 Object id = json[Response.ID]; | 473 Object id = json[Response.ID]; |
| 471 if (id is! String) { | 474 if (id is! String) { |
| 472 return null; | 475 return null; |
| 473 } | 476 } |
| 474 Object error = json[Response.ERROR]; | 477 Object error = json[Response.ERROR]; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 */ | 686 */ |
| 684 Map<String, Object> toJson() { | 687 Map<String, Object> toJson() { |
| 685 Map<String, Object> jsonObject = new Map<String, Object>(); | 688 Map<String, Object> jsonObject = new Map<String, Object>(); |
| 686 jsonObject[CODE] = code; | 689 jsonObject[CODE] = code; |
| 687 jsonObject[MESSAGE] = message; | 690 jsonObject[MESSAGE] = message; |
| 688 if (!data.isEmpty) { | 691 if (!data.isEmpty) { |
| 689 jsonObject[DATA] = data; | 692 jsonObject[DATA] = data; |
| 690 } | 693 } |
| 691 return jsonObject; | 694 return jsonObject; |
| 692 } | 695 } |
| 696 |
| 697 @override |
| 698 String toString() => toJson().toString(); |
| 693 } | 699 } |
| 694 | 700 |
| 695 /** | 701 /** |
| 696 * Instances of the class [Notification] represent a notification from the | 702 * Instances of the class [Notification] represent a notification from the |
| 697 * server about an event that occurred. | 703 * server about an event that occurred. |
| 698 */ | 704 */ |
| 699 class Notification { | 705 class Notification { |
| 700 /** | 706 /** |
| 701 * The name of the JSON attribute containing the name of the event that | 707 * The name of the JSON attribute containing the name of the event that |
| 702 * triggered the notification. | 708 * triggered the notification. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 /** | 798 /** |
| 793 * The response to be returned as a result of the failure. | 799 * The response to be returned as a result of the failure. |
| 794 */ | 800 */ |
| 795 final Response response; | 801 final Response response; |
| 796 | 802 |
| 797 /** | 803 /** |
| 798 * Initialize a newly created exception to return the given reponse. | 804 * Initialize a newly created exception to return the given reponse. |
| 799 */ | 805 */ |
| 800 RequestFailure(this.response); | 806 RequestFailure(this.response); |
| 801 } | 807 } |
| OLD | NEW |