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

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

Issue 238293006: Create analysis server ByteStreamServerChannel class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | pkg/analysis_server/test/channel_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6d60abda994f03cd79fb160437023509c103e269..850585b257d710dd0b9aa80228ecd53b3152265d 100644
--- a/pkg/analysis_server/lib/src/channel.dart
+++ b/pkg/analysis_server/lib/src/channel.dart
@@ -170,6 +170,51 @@ class WebSocketServerChannel implements ServerCommunicationChannel {
}
/**
+ * Instances of the class [ByteStreamServerChannel] implement a
+ * [ClientCommunicationChannel] that uses a stream and a sink (typically,
+ * standard input and standard output) to communicate with servers.
+ */
+class ByteStreamServerChannel implements ServerCommunicationChannel {
+ final Stream input;
+ final IOSink output;
+
+ ByteStreamServerChannel(this.input, this.output);
+
+ @override
+ void listen(void onRequest(Request request), {Function onError, void
+ onDone()}) {
+ input.transform((new Utf8Codec()).decoder).transform(new LineSplitter()
+ ).listen((String data) => _readRequest(data, onRequest), onError: onError,
+ onDone: onDone);
+ }
+
+ @override
+ void sendNotification(Notification notification) {
+ output.writeln(JSON.encode(notification.toJson()));
+ }
+
+ @override
+ void sendResponse(Response response) {
+ output.writeln(JSON.encode(response.toJson()));
+ }
+
+ /**
+ * Read a request from the given [data] and use the given function to handle
+ * the request.
+ */
+ void _readRequest(Object data, void onRequest(Request request)) {
+ // Parse the string as a JSON descriptor and process the resulting
+ // structure as a request.
+ Request request = new Request.fromString(data);
+ if (request == null) {
+ sendResponse(new Response.invalidRequestFormat());
+ return;
+ }
+ onRequest(request);
+ }
+}
+
+/**
* Instances of the class [JsonStreamDecoder] convert JSON strings to JSON
* maps.
*/
« no previous file with comments | « no previous file | pkg/analysis_server/test/channel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698