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

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

Issue 276113002: new ByteStreamClientChannel (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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
Index: pkg/analysis_server/lib/src/channel.dart
diff --git a/pkg/analysis_server/lib/src/channel.dart b/pkg/analysis_server/lib/src/channel.dart
index f6b32300f8f93d0adbb10b4f0a98afa233e956da..7ffec7044833e2722daf9ee10dc2c34611357301 100644
--- a/pkg/analysis_server/lib/src/channel.dart
+++ b/pkg/analysis_server/lib/src/channel.dart
@@ -170,10 +170,54 @@ class WebSocketServerChannel implements ServerCommunicationChannel {
}
/**
- * Instances of the class [ByteStreamServerChannel] implement a
+ * Instances of the class [ByteStreamClientChannel] implement a
* [ClientCommunicationChannel] that uses a stream and a sink (typically,
* standard input and standard output) to communicate with servers.
*/
+class ByteStreamClientChannel implements ClientCommunicationChannel {
+ final Stream input;
+ final IOSink output;
+
+ @override
+ Stream<Response> responseStream;
+
+ @override
+ Stream<Notification> notificationStream;
+
+ ByteStreamClientChannel(this.input, this.output) {
+ Stream jsonStream = input.transform((new Utf8Codec()).decoder)
+ .transform(new LineSplitter())
+ .transform(new JsonStreamDecoder())
+ .where((json) => json is Map)
+ .asBroadcastStream();
+ responseStream = jsonStream
+ .where((json) => json[Notification.EVENT] == null)
+ .transform(new ResponseConverter())
+ .asBroadcastStream();
+ notificationStream = jsonStream
+ .where((json) => json[Notification.EVENT] != null)
+ .transform(new NotificationConverter())
+ .asBroadcastStream();
+ }
+
+ @override
+ Future close() {
+ // TODO: implement close
+ }
+
+ @override
+ Future<Response> sendRequest(Request request) {
+ String id = request.id;
+ output.writeln(JSON.encode(request.toJson()));
+ return responseStream.firstWhere((Response response) => response.id == id);
+ }
+}
+
+/**
+ * Instances of the class [ByteStreamServerChannel] implement a
+ * [ServerCommunicationChannel] that uses a stream and a sink (typically,
+ * standard input and standard output) to communicate with clients.
+ */
class ByteStreamServerChannel implements ServerCommunicationChannel {
final Stream input;
final IOSink output;
« no previous file with comments | « no previous file | pkg/analysis_server/test/channel_test.dart » ('j') | pkg/analysis_server/test/channel_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698