From 415903f03fe2a16ba4d8a5f826ad68becf5e3266 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 23 Jan 2015 15:00:38 -0800 Subject: [PATCH] Removed unnecessary bidi stream wrappers --- surface_client.js | 42 +++-------------------------------------- surface_server.js | 48 ++--------------------------------------------- 2 files changed, 5 insertions(+), 85 deletions(-) diff --git a/surface_client.js b/surface_client.js index 8996f0be..abec999c 100644 --- a/surface_client.js +++ b/surface_client.js @@ -98,36 +98,9 @@ function ClientWritableObjectStream(stream) { }); } - -util.inherits(ClientBidiObjectStream, Duplex); - -/** - * Class for representing a gRPC bidi streaming call as a Node stream on the - * client side. Extends from stream.Duplex. - * @constructor - * @param {stream} stream Underlying binary Duplex stream for the call - */ -function ClientBidiObjectStream(stream) { - var options = {objectMode: true}; - Duplex.call(this, options); - this._stream = stream; - var self = this; - forwardEvent(stream, this, 'status'); - forwardEvent(stream, this, 'metadata'); - this._stream.on('data', function forwardData(chunk) { - if (!self.push(chunk)) { - self._stream.pause(); - } - }); - this._stream.pause(); - this.on('finish', function() { - this._stream.end(); - }); -} - /** * _read implementation for both types of streams that allow reading. - * @this {ClientReadableObjectStream|ClientBidiObjectStream} + * @this {ClientReadableObjectStream} * @param {number} size Ignored */ function _read(size) { @@ -138,14 +111,10 @@ function _read(size) { * See docs for _read */ ClientReadableObjectStream.prototype._read = _read; -/** - * See docs for _read - */ -ClientBidiObjectStream.prototype._read = _read; /** * _write implementation for both types of streams that allow writing - * @this {ClientWritableObjectStream|ClientBidiObjectStream} + * @this {ClientWritableObjectStream} * @param {*} chunk The value to write to the stream * @param {string} encoding Ignored * @param {function(Error)} callback Callback to call when finished writing @@ -158,10 +127,6 @@ function _write(chunk, encoding, callback) { * See docs for _write */ ClientWritableObjectStream.prototype._write = _write; -/** - * See docs for _write - */ -ClientBidiObjectStream.prototype._write = _write; /** * Get a function that can make unary requests to the specified method. @@ -297,8 +262,7 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { function makeBidiStreamRequest(metadata, deadline) { var stream = client.makeRequest(this.channel, method, serialize, deserialize, metadata, deadline); - var obj_stream = new ClientBidiObjectStream(stream); - return obj_stream; + return stream; } return makeBidiStreamRequest; } diff --git a/surface_server.js b/surface_server.js index 28af5ab4..e3c48b13 100644 --- a/surface_server.js +++ b/surface_server.js @@ -90,34 +90,6 @@ function ServerWritableObjectStream(stream) { this._stream.end(); }); } - -util.inherits(ServerBidiObjectStream, Duplex); - -/** - * Class for representing a gRPC bidi streaming call as a Node stream on the - * server side. Extends from stream.Duplex. - * @constructor - * @param {stream} stream Underlying binary Duplex stream for the call - */ -function ServerBidiObjectStream(stream) { - var options = {objectMode: true}; - Duplex.call(this, options); - this._stream = stream; - var self = this; - this._stream.on('data', function forwardData(chunk) { - if (!self.push(chunk)) { - self._stream.pause(); - } - }); - this._stream.on('end', function forwardEnd() { - self.push(null); - }); - this._stream.pause(); - this.on('finish', function() { - this._stream.end(); - }); -} - /** * _read implementation for both types of streams that allow reading. * @this {ServerReadableObjectStream|ServerBidiObjectStream} @@ -131,14 +103,10 @@ function _read(size) { * See docs for _read */ ServerReadableObjectStream.prototype._read = _read; -/** - * See docs for _read - */ -ServerBidiObjectStream.prototype._read = _read; /** * _write implementation for both types of streams that allow writing - * @this {ServerWritableObjectStream|ServerBidiObjectStream} + * @this {ServerWritableObjectStream} * @param {*} chunk The value to write to the stream * @param {string} encoding Ignored * @param {function(Error)} callback Callback to call when finished writing @@ -151,10 +119,6 @@ function _write(chunk, encoding, callback) { * See docs for _write */ ServerWritableObjectStream.prototype._write = _write; -/** - * See docs for _write - */ -ServerBidiObjectStream.prototype._write = _write; /** * Creates a binary stream handler function from a unary handler function @@ -238,15 +202,7 @@ function makeServerStreamHandler(handler) { * @return {function(stream)} Binary stream handler */ function makeBidiStreamHandler(handler) { - /** - * Handles a stream by wrapping it in a serializing and deserializing object - * stream, and passing it to the handler. - * @param {stream} stream Binary data stream - */ - return function handleBidiStreamCall(stream) { - var object_stream = new ServerBidiObjectStream(stream); - handler(object_stream); - }; + return handler; } /**