aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/surface_client.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/node/surface_client.js')
-rw-r--r--src/node/surface_client.js34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/node/surface_client.js b/src/node/surface_client.js
index acd22089ce..77dab5ca6f 100644
--- a/src/node/surface_client.js
+++ b/src/node/surface_client.js
@@ -35,6 +35,8 @@ var _ = require('underscore');
var client = require('./client.js');
+var common = require('./common.js');
+
var EventEmitter = require('events').EventEmitter;
var stream = require('stream');
@@ -44,6 +46,7 @@ var Writable = stream.Writable;
var Duplex = stream.Duplex;
var util = require('util');
+
function forwardEvent(fromEmitter, toEmitter, event) {
fromEmitter.on(event, function forward() {
_.partial(toEmitter.emit, event).apply(toEmitter, arguments);
@@ -317,16 +320,13 @@ var requester_makers = {
}
/**
- * Creates a constructor for clients with a service defined by the methods
- * object. The methods object has string keys and values of this form:
- * {serialize: function, deserialize: function, client_stream: bool,
- * server_stream: bool}
- * @param {!Object<string, Object>} methods Method descriptor for each method
- * the client should expose
- * @param {string} prefix The prefix to prepend to each method name
+ * Creates a constructor for clients for the given service
+ * @param {ProtoBuf.Reflect.Service} service The service to generate a client
+ * for
* @return {function(string, Object)} New client constructor
*/
-function makeClientConstructor(methods, prefix) {
+function makeClientConstructor(service) {
+ var prefix = '/' + common.fullyQualifiedName(service) + '/';
/**
* Create a client with the given methods
* @constructor
@@ -337,27 +337,29 @@ function makeClientConstructor(methods, prefix) {
this.channel = new client.Channel(address, options);
}
- _.each(methods, function(method, name) {
+ _.each(service.children, function(method) {
var method_type;
- if (method.client_stream) {
- if (method.server_stream) {
+ if (method.requestStream) {
+ if (method.responseStream) {
method_type = 'bidi';
} else {
method_type = 'client_stream';
}
} else {
- if (method.server_stream) {
+ if (method.responseStream) {
method_type = 'server_stream';
} else {
method_type = 'unary';
}
}
- SurfaceClient.prototype[name] = requester_makers[method_type](
- prefix + name,
- method.serialize,
- method.deserialize);
+ SurfaceClient.prototype[method.name] = requester_makers[method_type](
+ prefix + method.name,
+ common.serializeCls(method.resolvedRequestType.build()),
+ common.deserializeCls(method.resolvedResponseType.build()));
});
+ SurfaceClient.service = service;
+
return SurfaceClient;
}