| 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:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 part 'generated_protocol.dart'; | 10 part 'generated_protocol.dart'; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 * The name of the JSON attribute containing the name of the request. | 490 * The name of the JSON attribute containing the name of the request. |
| 491 */ | 491 */ |
| 492 static const String METHOD = 'method'; | 492 static const String METHOD = 'method'; |
| 493 | 493 |
| 494 /** | 494 /** |
| 495 * The name of the JSON attribute containing the request parameters. | 495 * The name of the JSON attribute containing the request parameters. |
| 496 */ | 496 */ |
| 497 static const String PARAMS = 'params'; | 497 static const String PARAMS = 'params'; |
| 498 | 498 |
| 499 /** | 499 /** |
| 500 * The name of the optional JSON attribute indicating the time |
| 501 * (milliseconds since epoch) at which the client made the request. |
| 502 */ |
| 503 static const String CLIENT_REQUEST_TIME = 'clientRequestTime'; |
| 504 |
| 505 /** |
| 500 * The unique identifier used to identify this request. | 506 * The unique identifier used to identify this request. |
| 501 */ | 507 */ |
| 502 final String id; | 508 final String id; |
| 503 | 509 |
| 504 /** | 510 /** |
| 505 * The method being requested. | 511 * The method being requested. |
| 506 */ | 512 */ |
| 507 final String method; | 513 final String method; |
| 508 | 514 |
| 509 /** | 515 /** |
| 510 * A table mapping the names of request parameters to their values. | 516 * A table mapping the names of request parameters to their values. |
| 511 */ | 517 */ |
| 512 final Map<String, Object> _params; | 518 final Map<String, Object> _params; |
| 513 | 519 |
| 514 /** | 520 /** |
| 521 * The time (milliseconds since epoch) at which the client made the request |
| 522 * or `null` if this information is not provided by the client. |
| 523 */ |
| 524 final int clientRequestTime; |
| 525 |
| 526 /** |
| 515 * Initialize a newly created [Request] to have the given [id] and [method] | 527 * Initialize a newly created [Request] to have the given [id] and [method] |
| 516 * name. If [params] is supplied, it is used as the "params" map for the | 528 * name. If [params] is supplied, it is used as the "params" map for the |
| 517 * request. Otherwise an empty "params" map is allocated. | 529 * request. Otherwise an empty "params" map is allocated. |
| 518 */ | 530 */ |
| 519 Request(this.id, this.method, [Map<String, Object> params]) | 531 Request(this.id, this.method, [Map<String, Object> params, |
| 532 this.clientRequestTime]) |
| 520 : _params = params != null ? params : new HashMap<String, Object>(); | 533 : _params = params != null ? params : new HashMap<String, Object>(); |
| 521 | 534 |
| 522 /** | 535 /** |
| 523 * Return a request parsed from the given [data], or `null` if the [data] is | 536 * Return a request parsed from the given [data], or `null` if the [data] is |
| 524 * not a valid json representation of a request. The [data] is expected to | 537 * not a valid json representation of a request. The [data] is expected to |
| 525 * have the following format: | 538 * have the following format: |
| 526 * | 539 * |
| 527 * { | 540 * { |
| 528 * 'id': String, | 541 * 'id': String, |
| 529 * 'method': methodName, | 542 * 'method': methodName, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 541 if (result is! Map) { | 554 if (result is! Map) { |
| 542 return null; | 555 return null; |
| 543 } | 556 } |
| 544 var id = result[Request.ID]; | 557 var id = result[Request.ID]; |
| 545 var method = result[Request.METHOD]; | 558 var method = result[Request.METHOD]; |
| 546 if (id is! String || method is! String) { | 559 if (id is! String || method is! String) { |
| 547 return null; | 560 return null; |
| 548 } | 561 } |
| 549 var params = result[Request.PARAMS]; | 562 var params = result[Request.PARAMS]; |
| 550 if (params is Map || params == null) { | 563 if (params is Map || params == null) { |
| 551 return new Request(id, method, params); | 564 var time = result[Request.CLIENT_REQUEST_TIME]; |
| 565 return new Request(id, method, params, time is int ? time : null); |
| 552 } else { | 566 } else { |
| 553 return null; | 567 return null; |
| 554 } | 568 } |
| 555 } catch (exception) { | 569 } catch (exception) { |
| 556 return null; | 570 return null; |
| 557 } | 571 } |
| 558 } | 572 } |
| 559 | 573 |
| 560 /** | 574 /** |
| 561 * Return a table representing the structure of the Json object that will be | 575 * Return a table representing the structure of the Json object that will be |
| 562 * sent to the client to represent this response. | 576 * sent to the client to represent this response. |
| 563 */ | 577 */ |
| 564 Map<String, Object> toJson() { | 578 Map<String, Object> toJson() { |
| 565 Map<String, Object> jsonObject = new HashMap<String, Object>(); | 579 Map<String, Object> jsonObject = new HashMap<String, Object>(); |
| 566 jsonObject[ID] = id; | 580 jsonObject[ID] = id; |
| 567 jsonObject[METHOD] = method; | 581 jsonObject[METHOD] = method; |
| 568 if (_params.isNotEmpty) { | 582 if (_params.isNotEmpty) { |
| 569 jsonObject[PARAMS] = _params; | 583 jsonObject[PARAMS] = _params; |
| 570 } | 584 } |
| 585 if (clientRequestTime != null) { |
| 586 jsonObject[CLIENT_REQUEST_TIME] = clientRequestTime; |
| 587 } |
| 571 return jsonObject; | 588 return jsonObject; |
| 572 } | 589 } |
| 573 } | 590 } |
| 574 | 591 |
| 575 | 592 |
| 576 /** | 593 /** |
| 577 * JsonDecoder for decoding requests. Errors are reporting by throwing a | 594 * JsonDecoder for decoding requests. Errors are reporting by throwing a |
| 578 * [RequestFailure]. | 595 * [RequestFailure]. |
| 579 */ | 596 */ |
| 580 class RequestDecoder extends JsonDecoder { | 597 class RequestDecoder extends JsonDecoder { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 /** | 701 /** |
| 685 * Initialize a newly created instance to represent a response to a request | 702 * Initialize a newly created instance to represent a response to a request |
| 686 * with the given [id]. If [_result] is provided, it will be used as the | 703 * with the given [id]. If [_result] is provided, it will be used as the |
| 687 * result; otherwise an empty result will be used. If an [error] is provided | 704 * result; otherwise an empty result will be used. If an [error] is provided |
| 688 * then the response will represent an error condition. | 705 * then the response will represent an error condition. |
| 689 */ | 706 */ |
| 690 Response(this.id, {Map<String, Object> result, this.error}) | 707 Response(this.id, {Map<String, Object> result, this.error}) |
| 691 : _result = result; | 708 : _result = result; |
| 692 | 709 |
| 693 /** | 710 /** |
| 711 * Initialize a newly created instance to represent the |
| 712 * FORMAT_INVALID_FILE error condition. |
| 713 */ |
| 714 Response.formatInvalidFile(Request request) |
| 715 : this( |
| 716 request.id, |
| 717 error: new RequestError( |
| 718 RequestErrorCode.FORMAT_INVALID_FILE, |
| 719 'Error during `edit.format`: invalid file.')); |
| 720 |
| 721 /** |
| 694 * Initialize a newly created instance based upon the given JSON data | 722 * Initialize a newly created instance based upon the given JSON data |
| 695 */ | 723 */ |
| 696 factory Response.fromJson(Map<String, Object> json) { | 724 factory Response.fromJson(Map<String, Object> json) { |
| 697 try { | 725 try { |
| 698 Object id = json[Response.ID]; | 726 Object id = json[Response.ID]; |
| 699 if (id is! String) { | 727 if (id is! String) { |
| 700 return null; | 728 return null; |
| 701 } | 729 } |
| 702 Object error = json[Response.ERROR]; | 730 Object error = json[Response.ERROR]; |
| 703 RequestError decodedError; | 731 RequestError decodedError; |
| 704 if (error is Map) { | 732 if (error is Map) { |
| 705 decodedError = | 733 decodedError = |
| 706 new RequestError.fromJson(new ResponseDecoder(null), '.error', error
); | 734 new RequestError.fromJson(new ResponseDecoder(null), '.error', error
); |
| 707 } | 735 } |
| 708 Object result = json[Response.RESULT]; | 736 Object result = json[Response.RESULT]; |
| 709 Map<String, Object> decodedResult; | 737 Map<String, Object> decodedResult; |
| 710 if (result is Map) { | 738 if (result is Map) { |
| 711 decodedResult = result; | 739 decodedResult = result; |
| 712 } | 740 } |
| 713 return new Response(id, error: decodedError, result: decodedResult); | 741 return new Response(id, error: decodedError, result: decodedResult); |
| 714 } catch (exception) { | 742 } catch (exception) { |
| 715 return null; | 743 return null; |
| 716 } | 744 } |
| 717 } | 745 } |
| 718 | 746 |
| 719 /** | 747 /** |
| 720 * Initialize a newly created instance to represent the | 748 * Initialize a newly created instance to represent the |
| 721 * FORMAT_INVALID_FILE error condition. | |
| 722 */ | |
| 723 Response.formatInvalidFile(Request request) | |
| 724 : this( | |
| 725 request.id, | |
| 726 error: new RequestError( | |
| 727 RequestErrorCode.FORMAT_INVALID_FILE, | |
| 728 'Error during `edit.format`: invalid file.')); | |
| 729 | |
| 730 /** | |
| 731 * Initialize a newly created instance to represent the | |
| 732 * GET_ERRORS_INVALID_FILE error condition. | 749 * GET_ERRORS_INVALID_FILE error condition. |
| 733 */ | 750 */ |
| 734 Response.getErrorsInvalidFile(Request request) | 751 Response.getErrorsInvalidFile(Request request) |
| 735 : this( | 752 : this( |
| 736 request.id, | 753 request.id, |
| 737 error: new RequestError( | 754 error: new RequestError( |
| 738 RequestErrorCode.GET_ERRORS_INVALID_FILE, | 755 RequestErrorCode.GET_ERRORS_INVALID_FILE, |
| 739 'Error during `analysis.getErrors`: invalid file.')); | 756 'Error during `analysis.getErrors`: invalid file.')); |
| 740 | 757 |
| 741 /** | 758 /** |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | 893 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
| 877 hash = hash ^ (hash >> 11); | 894 hash = hash ^ (hash >> 11); |
| 878 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | 895 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
| 879 } | 896 } |
| 880 | 897 |
| 881 static int hash2(a, b) => finish(combine(combine(0, a), b)); | 898 static int hash2(a, b) => finish(combine(combine(0, a), b)); |
| 882 | 899 |
| 883 static int hash4(a, b, c, d) => | 900 static int hash4(a, b, c, d) => |
| 884 finish(combine(combine(combine(combine(0, a), b), c), d)); | 901 finish(combine(combine(combine(combine(0, a), b), c), d)); |
| 885 } | 902 } |
| OLD | NEW |