aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/node/test/math
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2016-04-20 10:52:31 -0700
committerGravatar murgatroid99 <mlumish@google.com>2016-04-20 10:52:31 -0700
commit18997430ddefe0fe8db6888b8c466e4eca6198f7 (patch)
tree4c8498667ef705f8fe3e26abf31f01d5c2076cc0 /src/node/test/math
parentf8d7747ddd0f947c74d137f843cc32bde0e91eb3 (diff)
Use math test to test generated code
Diffstat (limited to 'src/node/test/math')
-rw-r--r--src/node/test/math/math_grpc_pb.js99
-rw-r--r--src/node/test/math/math_pb.js866
-rw-r--r--src/node/test/math/math_server.js40
3 files changed, 989 insertions, 16 deletions
diff --git a/src/node/test/math/math_grpc_pb.js b/src/node/test/math/math_grpc_pb.js
new file mode 100644
index 0000000000..083ed66913
--- /dev/null
+++ b/src/node/test/math/math_grpc_pb.js
@@ -0,0 +1,99 @@
+// GENERATED CODE -- DO NOT EDIT!
+
+'use strict';
+var grpc = require('grpc');
+var math_pb = require('./math_pb.js');
+
+function serialize_DivArgs(arg) {
+ if (!(arg instanceof math_pb.DivArgs)) {
+ throw new Error('Expected argument of type DivArgs');
+ }
+ return new Buffer(arg.serializeBinary());
+}
+
+function deserialize_DivArgs(buffer_arg) {
+ return math_pb.DivArgs.deserializeBinary(new Uint8Array(buffer_arg));
+}
+
+function serialize_DivReply(arg) {
+ if (!(arg instanceof math_pb.DivReply)) {
+ throw new Error('Expected argument of type DivReply');
+ }
+ return new Buffer(arg.serializeBinary());
+}
+
+function deserialize_DivReply(buffer_arg) {
+ return math_pb.DivReply.deserializeBinary(new Uint8Array(buffer_arg));
+}
+
+function serialize_FibArgs(arg) {
+ if (!(arg instanceof math_pb.FibArgs)) {
+ throw new Error('Expected argument of type FibArgs');
+ }
+ return new Buffer(arg.serializeBinary());
+}
+
+function deserialize_FibArgs(buffer_arg) {
+ return math_pb.FibArgs.deserializeBinary(new Uint8Array(buffer_arg));
+}
+
+function serialize_Num(arg) {
+ if (!(arg instanceof math_pb.Num)) {
+ throw new Error('Expected argument of type Num');
+ }
+ return new Buffer(arg.serializeBinary());
+}
+
+function deserialize_Num(buffer_arg) {
+ return math_pb.Num.deserializeBinary(new Uint8Array(buffer_arg));
+}
+
+
+var MathService = exports.MathService = {
+ div: {
+ path: '/math.Math/Div',
+ requestStream: false,
+ responseStream: false,
+ requestType: math_pb.DivArgs,
+ responseType: math_pb.DivReply,
+ requestSerialize: serialize_DivArgs,
+ requestDeserialize: deserialize_DivArgs,
+ responseSerialize: serialize_DivReply,
+ responseDeserialize: deserialize_DivReply,
+ },
+ divMany: {
+ path: '/math.Math/DivMany',
+ requestStream: true,
+ responseStream: true,
+ requestType: math_pb.DivArgs,
+ responseType: math_pb.DivReply,
+ requestSerialize: serialize_DivArgs,
+ requestDeserialize: deserialize_DivArgs,
+ responseSerialize: serialize_DivReply,
+ responseDeserialize: deserialize_DivReply,
+ },
+ fib: {
+ path: '/math.Math/Fib',
+ requestStream: false,
+ responseStream: true,
+ requestType: math_pb.FibArgs,
+ responseType: math_pb.Num,
+ requestSerialize: serialize_FibArgs,
+ requestDeserialize: deserialize_FibArgs,
+ responseSerialize: serialize_Num,
+ responseDeserialize: deserialize_Num,
+ },
+ sum: {
+ path: '/math.Math/Sum',
+ requestStream: true,
+ responseStream: false,
+ requestType: math_pb.Num,
+ responseType: math_pb.Num,
+ requestSerialize: serialize_Num,
+ requestDeserialize: deserialize_Num,
+ responseSerialize: serialize_Num,
+ responseDeserialize: deserialize_Num,
+ },
+};
+
+exports.MathClient = grpc.makeGenericClientConstructor(MathService);
diff --git a/src/node/test/math/math_pb.js b/src/node/test/math/math_pb.js
new file mode 100644
index 0000000000..3489143bec
--- /dev/null
+++ b/src/node/test/math/math_pb.js
@@ -0,0 +1,866 @@
+/**
+ * @fileoverview
+ * @enhanceable
+ * @public
+ */
+// GENERATED CODE -- DO NOT EDIT!
+
+var jspb = require('google-protobuf');
+var goog = jspb;
+var global = Function('return this')();
+
+goog.exportSymbol('proto.math.DivArgs', null, global);
+goog.exportSymbol('proto.math.DivReply', null, global);
+goog.exportSymbol('proto.math.FibArgs', null, global);
+goog.exportSymbol('proto.math.FibReply', null, global);
+goog.exportSymbol('proto.math.Num', null, global);
+
+/**
+ * Generated by JsPbCodeGenerator.
+ * @param {Array=} opt_data Optional initial data array, typically from a
+ * server response, or constructed directly in Javascript. The array is used
+ * in place and becomes part of the constructed object. It is not cloned.
+ * If no data is provided, the constructed object will be empty, but still
+ * valid.
+ * @extends {jspb.Message}
+ * @constructor
+ */
+proto.math.DivArgs = function(opt_data) {
+ jspb.Message.initialize(this, opt_data, 0, -1, null, null);
+};
+goog.inherits(proto.math.DivArgs, jspb.Message);
+if (goog.DEBUG && !COMPILED) {
+ proto.math.DivArgs.displayName = 'proto.math.DivArgs';
+}
+
+
+if (jspb.Message.GENERATE_TO_OBJECT) {
+/**
+ * Creates an object representation of this proto suitable for use in Soy templates.
+ * Field names that are reserved in JavaScript and will be renamed to pb_name.
+ * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
+ * For the list of reserved names please see:
+ * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
+ * @param {boolean=} opt_includeInstance Whether to include the JSPB instance
+ * for transitional soy proto support: http://goto/soy-param-migration
+ * @return {!Object}
+ */
+proto.math.DivArgs.prototype.toObject = function(opt_includeInstance) {
+ return proto.math.DivArgs.toObject(opt_includeInstance, this);
+};
+
+
+/**
+ * Static version of the {@see toObject} method.
+ * @param {boolean|undefined} includeInstance Whether to include the JSPB
+ * instance for transitional soy proto support:
+ * http://goto/soy-param-migration
+ * @param {!proto.math.DivArgs} msg The msg instance to transform.
+ * @return {!Object}
+ */
+proto.math.DivArgs.toObject = function(includeInstance, msg) {
+ var f, obj = {
+ dividend: msg.getDividend(),
+ divisor: msg.getDivisor()
+ };
+
+ if (includeInstance) {
+ obj.$jspbMessageInstance = msg
+ }
+ return obj;
+};
+}
+
+
+/**
+ * Deserializes binary data (in protobuf wire format).
+ * @param {jspb.ByteSource} bytes The bytes to deserialize.
+ * @return {!proto.math.DivArgs}
+ */
+proto.math.DivArgs.deserializeBinary = function(bytes) {
+ var reader = new jspb.BinaryReader(bytes);
+ var msg = new proto.math.DivArgs;
+ return proto.math.DivArgs.deserializeBinaryFromReader(msg, reader);
+};
+
+
+/**
+ * Deserializes binary data (in protobuf wire format) from the
+ * given reader into the given message object.
+ * @param {!proto.math.DivArgs} msg The message object to deserialize into.
+ * @param {!jspb.BinaryReader} reader The BinaryReader to use.
+ * @return {!proto.math.DivArgs}
+ */
+proto.math.DivArgs.deserializeBinaryFromReader = function(msg, reader) {
+ while (reader.nextField()) {
+ if (reader.isEndGroup()) {
+ break;
+ }
+ var field = reader.getFieldNumber();
+ switch (field) {
+ case 1:
+ var value = /** @type {number} */ (reader.readInt64());
+ msg.setDividend(value);
+ break;
+ case 2:
+ var value = /** @type {number} */ (reader.readInt64());
+ msg.setDivisor(value);
+ break;
+ default:
+ reader.skipField();
+ break;
+ }
+ }
+ return msg;
+};
+
+
+/**
+ * Class method variant: serializes the given message to binary data
+ * (in protobuf wire format), writing to the given BinaryWriter.
+ * @param {!proto.math.DivArgs} message
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.DivArgs.serializeBinaryToWriter = function(message, writer) {
+ message.serializeBinaryToWriter(writer);
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format).
+ * @return {!Uint8Array}
+ */
+proto.math.DivArgs.prototype.serializeBinary = function() {
+ var writer = new jspb.BinaryWriter();
+ this.serializeBinaryToWriter(writer);
+ return writer.getResultBuffer();
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format),
+ * writing to the given BinaryWriter.
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.DivArgs.prototype.serializeBinaryToWriter = function (writer) {
+ var f = undefined;
+ f = this.getDividend();
+ if (f !== 0) {
+ writer.writeInt64(
+ 1,
+ f
+ );
+ }
+ f = this.getDivisor();
+ if (f !== 0) {
+ writer.writeInt64(
+ 2,
+ f
+ );
+ }
+};
+
+
+/**
+ * Creates a deep clone of this proto. No data is shared with the original.
+ * @return {!proto.math.DivArgs} The clone.
+ */
+proto.math.DivArgs.prototype.cloneMessage = function() {
+ return /** @type {!proto.math.DivArgs} */ (jspb.Message.cloneMessage(this));
+};
+
+
+/**
+ * optional int64 dividend = 1;
+ * @return {number}
+ */
+proto.math.DivArgs.prototype.getDividend = function() {
+ return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
+};
+
+
+/** @param {number} value */
+proto.math.DivArgs.prototype.setDividend = function(value) {
+ jspb.Message.setField(this, 1, value);
+};
+
+
+/**
+ * optional int64 divisor = 2;
+ * @return {number}
+ */
+proto.math.DivArgs.prototype.getDivisor = function() {
+ return /** @type {number} */ (jspb.Message.getFieldProto3(this, 2, 0));
+};
+
+
+/** @param {number} value */
+proto.math.DivArgs.prototype.setDivisor = function(value) {
+ jspb.Message.setField(this, 2, value);
+};
+
+
+
+/**
+ * Generated by JsPbCodeGenerator.
+ * @param {Array=} opt_data Optional initial data array, typically from a
+ * server response, or constructed directly in Javascript. The array is used
+ * in place and becomes part of the constructed object. It is not cloned.
+ * If no data is provided, the constructed object will be empty, but still
+ * valid.
+ * @extends {jspb.Message}
+ * @constructor
+ */
+proto.math.DivReply = function(opt_data) {
+ jspb.Message.initialize(this, opt_data, 0, -1, null, null);
+};
+goog.inherits(proto.math.DivReply, jspb.Message);
+if (goog.DEBUG && !COMPILED) {
+ proto.math.DivReply.displayName = 'proto.math.DivReply';
+}
+
+
+if (jspb.Message.GENERATE_TO_OBJECT) {
+/**
+ * Creates an object representation of this proto suitable for use in Soy templates.
+ * Field names that are reserved in JavaScript and will be renamed to pb_name.
+ * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
+ * For the list of reserved names please see:
+ * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
+ * @param {boolean=} opt_includeInstance Whether to include the JSPB instance
+ * for transitional soy proto support: http://goto/soy-param-migration
+ * @return {!Object}
+ */
+proto.math.DivReply.prototype.toObject = function(opt_includeInstance) {
+ return proto.math.DivReply.toObject(opt_includeInstance, this);
+};
+
+
+/**
+ * Static version of the {@see toObject} method.
+ * @param {boolean|undefined} includeInstance Whether to include the JSPB
+ * instance for transitional soy proto support:
+ * http://goto/soy-param-migration
+ * @param {!proto.math.DivReply} msg The msg instance to transform.
+ * @return {!Object}
+ */
+proto.math.DivReply.toObject = function(includeInstance, msg) {
+ var f, obj = {
+ quotient: msg.getQuotient(),
+ remainder: msg.getRemainder()
+ };
+
+ if (includeInstance) {
+ obj.$jspbMessageInstance = msg
+ }
+ return obj;
+};
+}
+
+
+/**
+ * Deserializes binary data (in protobuf wire format).
+ * @param {jspb.ByteSource} bytes The bytes to deserialize.
+ * @return {!proto.math.DivReply}
+ */
+proto.math.DivReply.deserializeBinary = function(bytes) {
+ var reader = new jspb.BinaryReader(bytes);
+ var msg = new proto.math.DivReply;
+ return proto.math.DivReply.deserializeBinaryFromReader(msg, reader);
+};
+
+
+/**
+ * Deserializes binary data (in protobuf wire format) from the
+ * given reader into the given message object.
+ * @param {!proto.math.DivReply} msg The message object to deserialize into.
+ * @param {!jspb.BinaryReader} reader The BinaryReader to use.
+ * @return {!proto.math.DivReply}
+ */
+proto.math.DivReply.deserializeBinaryFromReader = function(msg, reader) {
+ while (reader.nextField()) {
+ if (reader.isEndGroup()) {
+ break;
+ }
+ var field = reader.getFieldNumber();
+ switch (field) {
+ case 1:
+ var value = /** @type {number} */ (reader.readInt64());
+ msg.setQuotient(value);
+ break;
+ case 2:
+ var value = /** @type {number} */ (reader.readInt64());
+ msg.setRemainder(value);
+ break;
+ default:
+ reader.skipField();
+ break;
+ }
+ }
+ return msg;
+};
+
+
+/**
+ * Class method variant: serializes the given message to binary data
+ * (in protobuf wire format), writing to the given BinaryWriter.
+ * @param {!proto.math.DivReply} message
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.DivReply.serializeBinaryToWriter = function(message, writer) {
+ message.serializeBinaryToWriter(writer);
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format).
+ * @return {!Uint8Array}
+ */
+proto.math.DivReply.prototype.serializeBinary = function() {
+ var writer = new jspb.BinaryWriter();
+ this.serializeBinaryToWriter(writer);
+ return writer.getResultBuffer();
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format),
+ * writing to the given BinaryWriter.
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.DivReply.prototype.serializeBinaryToWriter = function (writer) {
+ var f = undefined;
+ f = this.getQuotient();
+ if (f !== 0) {
+ writer.writeInt64(
+ 1,
+ f
+ );
+ }
+ f = this.getRemainder();
+ if (f !== 0) {
+ writer.writeInt64(
+ 2,
+ f
+ );
+ }
+};
+
+
+/**
+ * Creates a deep clone of this proto. No data is shared with the original.
+ * @return {!proto.math.DivReply} The clone.
+ */
+proto.math.DivReply.prototype.cloneMessage = function() {
+ return /** @type {!proto.math.DivReply} */ (jspb.Message.cloneMessage(this));
+};
+
+
+/**
+ * optional int64 quotient = 1;
+ * @return {number}
+ */
+proto.math.DivReply.prototype.getQuotient = function() {
+ return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
+};
+
+
+/** @param {number} value */
+proto.math.DivReply.prototype.setQuotient = function(value) {
+ jspb.Message.setField(this, 1, value);
+};
+
+
+/**
+ * optional int64 remainder = 2;
+ * @return {number}
+ */
+proto.math.DivReply.prototype.getRemainder = function() {
+ return /** @type {number} */ (jspb.Message.getFieldProto3(this, 2, 0));
+};
+
+
+/** @param {number} value */
+proto.math.DivReply.prototype.setRemainder = function(value) {
+ jspb.Message.setField(this, 2, value);
+};
+
+
+
+/**
+ * Generated by JsPbCodeGenerator.
+ * @param {Array=} opt_data Optional initial data array, typically from a
+ * server response, or constructed directly in Javascript. The array is used
+ * in place and becomes part of the constructed object. It is not cloned.
+ * If no data is provided, the constructed object will be empty, but still
+ * valid.
+ * @extends {jspb.Message}
+ * @constructor
+ */
+proto.math.FibArgs = function(opt_data) {
+ jspb.Message.initialize(this, opt_data, 0, -1, null, null);
+};
+goog.inherits(proto.math.FibArgs, jspb.Message);
+if (goog.DEBUG && !COMPILED) {
+ proto.math.FibArgs.displayName = 'proto.math.FibArgs';
+}
+
+
+if (jspb.Message.GENERATE_TO_OBJECT) {
+/**
+ * Creates an object representation of this proto suitable for use in Soy templates.
+ * Field names that are reserved in JavaScript and will be renamed to pb_name.
+ * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
+ * For the list of reserved names please see:
+ * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
+ * @param {boolean=} opt_includeInstance Whether to include the JSPB instance
+ * for transitional soy proto support: http://goto/soy-param-migration
+ * @return {!Object}
+ */
+proto.math.FibArgs.prototype.toObject = function(opt_includeInstance) {
+ return proto.math.FibArgs.toObject(opt_includeInstance, this);
+};
+
+
+/**
+ * Static version of the {@see toObject} method.
+ * @param {boolean|undefined} includeInstance Whether to include the JSPB
+ * instance for transitional soy proto support:
+ * http://goto/soy-param-migration
+ * @param {!proto.math.FibArgs} msg The msg instance to transform.
+ * @return {!Object}
+ */
+proto.math.FibArgs.toObject = function(includeInstance, msg) {
+ var f, obj = {
+ limit: msg.getLimit()
+ };
+
+ if (includeInstance) {
+ obj.$jspbMessageInstance = msg
+ }
+ return obj;
+};
+}
+
+
+/**
+ * Deserializes binary data (in protobuf wire format).
+ * @param {jspb.ByteSource} bytes The bytes to deserialize.
+ * @return {!proto.math.FibArgs}
+ */
+proto.math.FibArgs.deserializeBinary = function(bytes) {
+ var reader = new jspb.BinaryReader(bytes);
+ var msg = new proto.math.FibArgs;
+ return proto.math.FibArgs.deserializeBinaryFromReader(msg, reader);
+};
+
+
+/**
+ * Deserializes binary data (in protobuf wire format) from the
+ * given reader into the given message object.
+ * @param {!proto.math.FibArgs} msg The message object to deserialize into.
+ * @param {!jspb.BinaryReader} reader The BinaryReader to use.
+ * @return {!proto.math.FibArgs}
+ */
+proto.math.FibArgs.deserializeBinaryFromReader = function(msg, reader) {
+ while (reader.nextField()) {
+ if (reader.isEndGroup()) {
+ break;
+ }
+ var field = reader.getFieldNumber();
+ switch (field) {
+ case 1:
+ var value = /** @type {number} */ (reader.readInt64());
+ msg.setLimit(value);
+ break;
+ default:
+ reader.skipField();
+ break;
+ }
+ }
+ return msg;
+};
+
+
+/**
+ * Class method variant: serializes the given message to binary data
+ * (in protobuf wire format), writing to the given BinaryWriter.
+ * @param {!proto.math.FibArgs} message
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.FibArgs.serializeBinaryToWriter = function(message, writer) {
+ message.serializeBinaryToWriter(writer);
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format).
+ * @return {!Uint8Array}
+ */
+proto.math.FibArgs.prototype.serializeBinary = function() {
+ var writer = new jspb.BinaryWriter();
+ this.serializeBinaryToWriter(writer);
+ return writer.getResultBuffer();
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format),
+ * writing to the given BinaryWriter.
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.FibArgs.prototype.serializeBinaryToWriter = function (writer) {
+ var f = undefined;
+ f = this.getLimit();
+ if (f !== 0) {
+ writer.writeInt64(
+ 1,
+ f
+ );
+ }
+};
+
+
+/**
+ * Creates a deep clone of this proto. No data is shared with the original.
+ * @return {!proto.math.FibArgs} The clone.
+ */
+proto.math.FibArgs.prototype.cloneMessage = function() {
+ return /** @type {!proto.math.FibArgs} */ (jspb.Message.cloneMessage(this));
+};
+
+
+/**
+ * optional int64 limit = 1;
+ * @return {number}
+ */
+proto.math.FibArgs.prototype.getLimit = function() {
+ return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
+};
+
+
+/** @param {number} value */
+proto.math.FibArgs.prototype.setLimit = function(value) {
+ jspb.Message.setField(this, 1, value);
+};
+
+
+
+/**
+ * Generated by JsPbCodeGenerator.
+ * @param {Array=} opt_data Optional initial data array, typically from a
+ * server response, or constructed directly in Javascript. The array is used
+ * in place and becomes part of the constructed object. It is not cloned.
+ * If no data is provided, the constructed object will be empty, but still
+ * valid.
+ * @extends {jspb.Message}
+ * @constructor
+ */
+proto.math.Num = function(opt_data) {
+ jspb.Message.initialize(this, opt_data, 0, -1, null, null);
+};
+goog.inherits(proto.math.Num, jspb.Message);
+if (goog.DEBUG && !COMPILED) {
+ proto.math.Num.displayName = 'proto.math.Num';
+}
+
+
+if (jspb.Message.GENERATE_TO_OBJECT) {
+/**
+ * Creates an object representation of this proto suitable for use in Soy templates.
+ * Field names that are reserved in JavaScript and will be renamed to pb_name.
+ * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
+ * For the list of reserved names please see:
+ * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
+ * @param {boolean=} opt_includeInstance Whether to include the JSPB instance
+ * for transitional soy proto support: http://goto/soy-param-migration
+ * @return {!Object}
+ */
+proto.math.Num.prototype.toObject = function(opt_includeInstance) {
+ return proto.math.Num.toObject(opt_includeInstance, this);
+};
+
+
+/**
+ * Static version of the {@see toObject} method.
+ * @param {boolean|undefined} includeInstance Whether to include the JSPB
+ * instance for transitional soy proto support:
+ * http://goto/soy-param-migration
+ * @param {!proto.math.Num} msg The msg instance to transform.
+ * @return {!Object}
+ */
+proto.math.Num.toObject = function(includeInstance, msg) {
+ var f, obj = {
+ num: msg.getNum()
+ };
+
+ if (includeInstance) {
+ obj.$jspbMessageInstance = msg
+ }
+ return obj;
+};
+}
+
+
+/**
+ * Deserializes binary data (in protobuf wire format).
+ * @param {jspb.ByteSource} bytes The bytes to deserialize.
+ * @return {!proto.math.Num}
+ */
+proto.math.Num.deserializeBinary = function(bytes) {
+ var reader = new jspb.BinaryReader(bytes);
+ var msg = new proto.math.Num;
+ return proto.math.Num.deserializeBinaryFromReader(msg, reader);
+};
+
+
+/**
+ * Deserializes binary data (in protobuf wire format) from the
+ * given reader into the given message object.
+ * @param {!proto.math.Num} msg The message object to deserialize into.
+ * @param {!jspb.BinaryReader} reader The BinaryReader to use.
+ * @return {!proto.math.Num}
+ */
+proto.math.Num.deserializeBinaryFromReader = function(msg, reader) {
+ while (reader.nextField()) {
+ if (reader.isEndGroup()) {
+ break;
+ }
+ var field = reader.getFieldNumber();
+ switch (field) {
+ case 1:
+ var value = /** @type {number} */ (reader.readInt64());
+ msg.setNum(value);
+ break;
+ default:
+ reader.skipField();
+ break;
+ }
+ }
+ return msg;
+};
+
+
+/**
+ * Class method variant: serializes the given message to binary data
+ * (in protobuf wire format), writing to the given BinaryWriter.
+ * @param {!proto.math.Num} message
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.Num.serializeBinaryToWriter = function(message, writer) {
+ message.serializeBinaryToWriter(writer);
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format).
+ * @return {!Uint8Array}
+ */
+proto.math.Num.prototype.serializeBinary = function() {
+ var writer = new jspb.BinaryWriter();
+ this.serializeBinaryToWriter(writer);
+ return writer.getResultBuffer();
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format),
+ * writing to the given BinaryWriter.
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.Num.prototype.serializeBinaryToWriter = function (writer) {
+ var f = undefined;
+ f = this.getNum();
+ if (f !== 0) {
+ writer.writeInt64(
+ 1,
+ f
+ );
+ }
+};
+
+
+/**
+ * Creates a deep clone of this proto. No data is shared with the original.
+ * @return {!proto.math.Num} The clone.
+ */
+proto.math.Num.prototype.cloneMessage = function() {
+ return /** @type {!proto.math.Num} */ (jspb.Message.cloneMessage(this));
+};
+
+
+/**
+ * optional int64 num = 1;
+ * @return {number}
+ */
+proto.math.Num.prototype.getNum = function() {
+ return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
+};
+
+
+/** @param {number} value */
+proto.math.Num.prototype.setNum = function(value) {
+ jspb.Message.setField(this, 1, value);
+};
+
+
+
+/**
+ * Generated by JsPbCodeGenerator.
+ * @param {Array=} opt_data Optional initial data array, typically from a
+ * server response, or constructed directly in Javascript. The array is used
+ * in place and becomes part of the constructed object. It is not cloned.
+ * If no data is provided, the constructed object will be empty, but still
+ * valid.
+ * @extends {jspb.Message}
+ * @constructor
+ */
+proto.math.FibReply = function(opt_data) {
+ jspb.Message.initialize(this, opt_data, 0, -1, null, null);
+};
+goog.inherits(proto.math.FibReply, jspb.Message);
+if (goog.DEBUG && !COMPILED) {
+ proto.math.FibReply.displayName = 'proto.math.FibReply';
+}
+
+
+if (jspb.Message.GENERATE_TO_OBJECT) {
+/**
+ * Creates an object representation of this proto suitable for use in Soy templates.
+ * Field names that are reserved in JavaScript and will be renamed to pb_name.
+ * To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
+ * For the list of reserved names please see:
+ * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
+ * @param {boolean=} opt_includeInstance Whether to include the JSPB instance
+ * for transitional soy proto support: http://goto/soy-param-migration
+ * @return {!Object}
+ */
+proto.math.FibReply.prototype.toObject = function(opt_includeInstance) {
+ return proto.math.FibReply.toObject(opt_includeInstance, this);
+};
+
+
+/**
+ * Static version of the {@see toObject} method.
+ * @param {boolean|undefined} includeInstance Whether to include the JSPB
+ * instance for transitional soy proto support:
+ * http://goto/soy-param-migration
+ * @param {!proto.math.FibReply} msg The msg instance to transform.
+ * @return {!Object}
+ */
+proto.math.FibReply.toObject = function(includeInstance, msg) {
+ var f, obj = {
+ count: msg.getCount()
+ };
+
+ if (includeInstance) {
+ obj.$jspbMessageInstance = msg
+ }
+ return obj;
+};
+}
+
+
+/**
+ * Deserializes binary data (in protobuf wire format).
+ * @param {jspb.ByteSource} bytes The bytes to deserialize.
+ * @return {!proto.math.FibReply}
+ */
+proto.math.FibReply.deserializeBinary = function(bytes) {
+ var reader = new jspb.BinaryReader(bytes);
+ var msg = new proto.math.FibReply;
+ return proto.math.FibReply.deserializeBinaryFromReader(msg, reader);
+};
+
+
+/**
+ * Deserializes binary data (in protobuf wire format) from the
+ * given reader into the given message object.
+ * @param {!proto.math.FibReply} msg The message object to deserialize into.
+ * @param {!jspb.BinaryReader} reader The BinaryReader to use.
+ * @return {!proto.math.FibReply}
+ */
+proto.math.FibReply.deserializeBinaryFromReader = function(msg, reader) {
+ while (reader.nextField()) {
+ if (reader.isEndGroup()) {
+ break;
+ }
+ var field = reader.getFieldNumber();
+ switch (field) {
+ case 1:
+ var value = /** @type {number} */ (reader.readInt64());
+ msg.setCount(value);
+ break;
+ default:
+ reader.skipField();
+ break;
+ }
+ }
+ return msg;
+};
+
+
+/**
+ * Class method variant: serializes the given message to binary data
+ * (in protobuf wire format), writing to the given BinaryWriter.
+ * @param {!proto.math.FibReply} message
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.FibReply.serializeBinaryToWriter = function(message, writer) {
+ message.serializeBinaryToWriter(writer);
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format).
+ * @return {!Uint8Array}
+ */
+proto.math.FibReply.prototype.serializeBinary = function() {
+ var writer = new jspb.BinaryWriter();
+ this.serializeBinaryToWriter(writer);
+ return writer.getResultBuffer();
+};
+
+
+/**
+ * Serializes the message to binary data (in protobuf wire format),
+ * writing to the given BinaryWriter.
+ * @param {!jspb.BinaryWriter} writer
+ */
+proto.math.FibReply.prototype.serializeBinaryToWriter = function (writer) {
+ var f = undefined;
+ f = this.getCount();
+ if (f !== 0) {
+ writer.writeInt64(
+ 1,
+ f
+ );
+ }
+};
+
+
+/**
+ * Creates a deep clone of this proto. No data is shared with the original.
+ * @return {!proto.math.FibReply} The clone.
+ */
+proto.math.FibReply.prototype.cloneMessage = function() {
+ return /** @type {!proto.math.FibReply} */ (jspb.Message.cloneMessage(this));
+};
+
+
+/**
+ * optional int64 count = 1;
+ * @return {number}
+ */
+proto.math.FibReply.prototype.getCount = function() {
+ return /** @type {number} */ (jspb.Message.getFieldProto3(this, 1, 0));
+};
+
+
+/** @param {number} value */
+proto.math.FibReply.prototype.setCount = function(value) {
+ jspb.Message.setField(this, 1, value);
+};
+
+
+goog.object.extend(exports, proto.math);
diff --git a/src/node/test/math/math_server.js b/src/node/test/math/math_server.js
index 9f67c52ab0..fa05ed0165 100644
--- a/src/node/test/math/math_server.js
+++ b/src/node/test/math/math_server.js
@@ -34,8 +34,8 @@
'use strict';
var grpc = require('../..');
-var math = grpc.load(__dirname + '/../../../proto/math/math.proto').math;
-
+var grpcMath = require('./math_grpc_pb');
+var math = require('./math_pb');
/**
* Server function for division. Provides the /Math/DivMany and /Math/Div
@@ -46,14 +46,16 @@ var math = grpc.load(__dirname + '/../../../proto/math/math.proto').math;
*/
function mathDiv(call, cb) {
var req = call.request;
+ var divisor = req.getDivisor();
+ var dividend = req.getDividend();
// Unary + is explicit coersion to integer
- if (+req.divisor === 0) {
+ if (req.getDivisor() === 0) {
cb(new Error('cannot divide by zero'));
} else {
- cb(null, {
- quotient: req.dividend / req.divisor,
- remainder: req.dividend % req.divisor
- });
+ var response = new math.DivReply();
+ response.setQuotient(Math.floor(dividend / divisor));
+ response.setRemainder(dividend % divisor);
+ cb(null, response);
}
}
@@ -67,7 +69,9 @@ function mathFib(stream) {
// Here, call is a standard writable Node object Stream
var previous = 0, current = 1;
for (var i = 0; i < stream.request.limit; i++) {
- stream.write({num: current});
+ var response = new math.Num();
+ response.setNum(current);
+ stream.write(response);
var temp = current;
current += previous;
previous = temp;
@@ -85,22 +89,26 @@ function mathSum(call, cb) {
// Here, call is a standard readable Node object Stream
var sum = 0;
call.on('data', function(data) {
- sum += (+data.num);
+ sum += data.getNum();
});
call.on('end', function() {
- cb(null, {num: sum});
+ var response = new math.Num();
+ response.setNum(sum);
+ cb(null, response);
});
}
function mathDivMany(stream) {
stream.on('data', function(div_args) {
- if (+div_args.divisor === 0) {
+ var divisor = div_args.getDivisor();
+ var dividend = div_args.getDividend();
+ if (divisor === 0) {
stream.emit('error', new Error('cannot divide by zero'));
} else {
- stream.write({
- quotient: div_args.dividend / div_args.divisor,
- remainder: div_args.dividend % div_args.divisor
- });
+ var response = new math.DivReply();
+ response.setQuotient(Math.floor(dividend / divisor));
+ response.setRemainder(dividend % divisor);
+ stream.write(response);
}
});
stream.on('end', function() {
@@ -110,7 +118,7 @@ function mathDivMany(stream) {
function getMathServer() {
var server = new grpc.Server();
- server.addProtoService(math.Math.service, {
+ server.addService(grpcMath.MathService, {
div: mathDiv,
fib: mathFib,
sum: mathSum,