aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2016-05-20 13:24:59 -0700
committerGravatar murgatroid99 <mlumish@google.com>2016-05-20 13:24:59 -0700
commit210f3c4b8e3088fc26e674841c7c992ef1c7d609 (patch)
tree23a3744021eb06dc270e507faf657de950113ddc
parent3c62c555a4d1b4385d4f8c6c9f533c34c82cec5a (diff)
Added comments to node generation, also refactored some plugin code
-rw-r--r--examples/node/static_codegen/helloworld_grpc_pb.js32
-rw-r--r--examples/node/static_codegen/helloworld_pb.js4
-rw-r--r--examples/node/static_codegen/route_guide/route_guide_grpc_pb.js51
-rw-r--r--examples/node/static_codegen/route_guide/route_guide_pb.js10
-rw-r--r--src/compiler/cpp_generator_helpers.h7
-rw-r--r--src/compiler/cpp_plugin.cc2
-rw-r--r--src/compiler/csharp_generator.cc3
-rw-r--r--src/compiler/csharp_generator_helpers.h7
-rw-r--r--src/compiler/generator_helpers.h8
-rw-r--r--src/compiler/node_generator.cc103
-rw-r--r--src/compiler/node_generator.h6
-rw-r--r--src/compiler/node_generator_helpers.h7
-rw-r--r--src/compiler/node_plugin.cc8
-rw-r--r--src/node/test/math/math_grpc_pb.js75
-rw-r--r--src/node/test/math/math_pb.js10
15 files changed, 233 insertions, 100 deletions
diff --git a/examples/node/static_codegen/helloworld_grpc_pb.js b/examples/node/static_codegen/helloworld_grpc_pb.js
index 846f8b6bf5..7a8dce4d23 100644
--- a/examples/node/static_codegen/helloworld_grpc_pb.js
+++ b/examples/node/static_codegen/helloworld_grpc_pb.js
@@ -1,5 +1,35 @@
// GENERATED CODE -- DO NOT EDIT!
+// Original file comments:
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
'use strict';
var grpc = require('grpc');
var helloworld_pb = require('./helloworld_pb.js');
@@ -27,7 +57,9 @@ function deserialize_HelloRequest(buffer_arg) {
}
+// The greeting service definition.
var GreeterService = exports.GreeterService = {
+ // Sends a greeting
sayHello: {
path: '/helloworld.Greeter/SayHello',
requestStream: false,
diff --git a/examples/node/static_codegen/helloworld_pb.js b/examples/node/static_codegen/helloworld_pb.js
index 6405bd90f1..d1e50c90ea 100644
--- a/examples/node/static_codegen/helloworld_pb.js
+++ b/examples/node/static_codegen/helloworld_pb.js
@@ -61,7 +61,7 @@ proto.helloworld.HelloRequest.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -220,7 +220,7 @@ proto.helloworld.HelloReply.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
diff --git a/examples/node/static_codegen/route_guide/route_guide_grpc_pb.js b/examples/node/static_codegen/route_guide/route_guide_grpc_pb.js
index 1dd71331db..ce030c8a3b 100644
--- a/examples/node/static_codegen/route_guide/route_guide_grpc_pb.js
+++ b/examples/node/static_codegen/route_guide/route_guide_grpc_pb.js
@@ -1,5 +1,35 @@
// GENERATED CODE -- DO NOT EDIT!
+// Original file comments:
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
'use strict';
var grpc = require('grpc');
var route_guide_pb = require('./route_guide_pb.js');
@@ -60,7 +90,14 @@ function deserialize_RouteSummary(buffer_arg) {
}
+// Interface exported by the server.
var RouteGuideService = exports.RouteGuideService = {
+ // A simple RPC.
+ //
+ // Obtains the feature at a given position.
+ //
+ // A feature with an empty name is returned if there's no feature at the given
+ // position.
getFeature: {
path: '/routeguide.RouteGuide/GetFeature',
requestStream: false,
@@ -72,6 +109,12 @@ var RouteGuideService = exports.RouteGuideService = {
responseSerialize: serialize_Feature,
responseDeserialize: deserialize_Feature,
},
+ // A server-to-client streaming RPC.
+ //
+ // Obtains the Features available within the given Rectangle. Results are
+ // streamed rather than returned at once (e.g. in a response message with a
+ // repeated field), as the rectangle may cover a large area and contain a
+ // huge number of features.
listFeatures: {
path: '/routeguide.RouteGuide/ListFeatures',
requestStream: false,
@@ -83,6 +126,10 @@ var RouteGuideService = exports.RouteGuideService = {
responseSerialize: serialize_Feature,
responseDeserialize: deserialize_Feature,
},
+ // A client-to-server streaming RPC.
+ //
+ // Accepts a stream of Points on a route being traversed, returning a
+ // RouteSummary when traversal is completed.
recordRoute: {
path: '/routeguide.RouteGuide/RecordRoute',
requestStream: true,
@@ -94,6 +141,10 @@ var RouteGuideService = exports.RouteGuideService = {
responseSerialize: serialize_RouteSummary,
responseDeserialize: deserialize_RouteSummary,
},
+ // A Bidirectional streaming RPC.
+ //
+ // Accepts a stream of RouteNotes sent while a route is being traversed,
+ // while receiving other RouteNotes (e.g. from other users).
routeChat: {
path: '/routeguide.RouteGuide/RouteChat',
requestStream: true,
diff --git a/examples/node/static_codegen/route_guide/route_guide_pb.js b/examples/node/static_codegen/route_guide/route_guide_pb.js
index f604cd6d50..2e2f9a1da2 100644
--- a/examples/node/static_codegen/route_guide/route_guide_pb.js
+++ b/examples/node/static_codegen/route_guide/route_guide_pb.js
@@ -65,7 +65,7 @@ proto.routeguide.Point.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -251,7 +251,7 @@ proto.routeguide.Rectangle.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -453,7 +453,7 @@ proto.routeguide.Feature.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -647,7 +647,7 @@ proto.routeguide.RouteNote.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -843,7 +843,7 @@ proto.routeguide.RouteSummary.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
diff --git a/src/compiler/cpp_generator_helpers.h b/src/compiler/cpp_generator_helpers.h
index be68cbe695..87e278f1b9 100644
--- a/src/compiler/cpp_generator_helpers.h
+++ b/src/compiler/cpp_generator_helpers.h
@@ -65,6 +65,13 @@ inline grpc::string ClassName(const grpc::protobuf::Descriptor *descriptor,
}
}
+// Get leading or trailing comments in a string. Comment lines start with "// ".
+// Leading detached comments are put in in front of leading comments.
+template <typename DescriptorType>
+inline grpc::string GetCppComments(const DescriptorType *desc, bool leading) {
+ return grpc_generator::GetPrefixedComments(desc, leading, "//");
+}
+
} // namespace grpc_cpp_generator
#endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_HELPERS_H
diff --git a/src/compiler/cpp_plugin.cc b/src/compiler/cpp_plugin.cc
index 0ec183e474..fc0296cd28 100644
--- a/src/compiler/cpp_plugin.cc
+++ b/src/compiler/cpp_plugin.cc
@@ -43,7 +43,7 @@
#include "src/compiler/cpp_generator_helpers.h"
#include "src/compiler/generator_helpers.h"
-using grpc_generator::GetCppComments;
+using grpc_cpp_generator::GetCppComments;
class ProtoBufMethod : public grpc_cpp_generator::Method {
public:
diff --git a/src/compiler/csharp_generator.cc b/src/compiler/csharp_generator.cc
index 29c359c539..484fa3cdcc 100644
--- a/src/compiler/csharp_generator.cc
+++ b/src/compiler/csharp_generator.cc
@@ -52,7 +52,6 @@ using grpc::protobuf::MethodDescriptor;
using grpc::protobuf::io::Printer;
using grpc::protobuf::io::StringOutputStream;
using grpc_generator::MethodType;
-using grpc_generator::GetCppComments;
using grpc_generator::GetMethodType;
using grpc_generator::METHODTYPE_NO_STREAMING;
using grpc_generator::METHODTYPE_CLIENT_STREAMING;
@@ -659,7 +658,7 @@ grpc::string GetServices(const FileDescriptor *file, bool generate_client,
out.Print("// source: $filename$\n", "filename", file->name());
// use C++ style as there are no file-level XML comments in .NET
- grpc::string leading_comments = GetCppComments(file, true);
+ grpc::string leading_comments = GetCsharpComments(file, true);
if (!leading_comments.empty()) {
out.Print("// Original file comments:\n");
out.Print(leading_comments.c_str());
diff --git a/src/compiler/csharp_generator_helpers.h b/src/compiler/csharp_generator_helpers.h
index 5639ea058b..9bdf6fb535 100644
--- a/src/compiler/csharp_generator_helpers.h
+++ b/src/compiler/csharp_generator_helpers.h
@@ -45,6 +45,13 @@ inline bool ServicesFilename(const grpc::protobuf::FileDescriptor *file,
return true;
}
+// Get leading or trailing comments in a string. Comment lines start with "// ".
+// Leading detached comments are put in in front of leading comments.
+template <typename DescriptorType>
+inline grpc::string GetCsharpComments(const DescriptorType *desc, bool leading) {
+ return grpc_generator::GetPrefixedComments(desc, leading, "//");
+}
+
} // namespace grpc_csharp_generator
#endif // GRPC_INTERNAL_COMPILER_CSHARP_GENERATOR_HELPERS_H
diff --git a/src/compiler/generator_helpers.h b/src/compiler/generator_helpers.h
index bd077cf798..53391bc41a 100644
--- a/src/compiler/generator_helpers.h
+++ b/src/compiler/generator_helpers.h
@@ -265,10 +265,10 @@ inline grpc::string GenerateCommentsWithPrefix(
return oss.str();
}
-// Get leading or trailing comments in a string. Comment lines start with "// ".
-// Leading detached comments are put in in front of leading comments.
template <typename DescriptorType>
-inline grpc::string GetCppComments(const DescriptorType *desc, bool leading) {
+inline grpc::string GetPrefixedComments(const DescriptorType *desc,
+ bool leading,
+ const grpc::string &prefix) {
std::vector<grpc::string> out;
if (leading) {
grpc_generator::GetComment(
@@ -281,7 +281,7 @@ inline grpc::string GetCppComments(const DescriptorType *desc, bool leading) {
grpc_generator::GetComment(desc, grpc_generator::COMMENTTYPE_TRAILING,
&out);
}
- return GenerateCommentsWithPrefix(out, "//");
+ return GenerateCommentsWithPrefix(out, prefix);
}
} // namespace grpc_generator
diff --git a/src/compiler/node_generator.cc b/src/compiler/node_generator.cc
index 822622cccf..986b97c26e 100644
--- a/src/compiler/node_generator.cc
+++ b/src/compiler/node_generator.cc
@@ -181,62 +181,67 @@ void PrintMethod(const MethodDescriptor *method, Printer *out) {
// Prints out the service descriptor object
void PrintService(const ServiceDescriptor *service, Printer *out) {
map<grpc::string, grpc::string> template_vars;
+ out->Print(GetNodeComments(service, true).c_str());
template_vars["name"] = service->name();
out->Print(template_vars, "var $name$Service = exports.$name$Service = {\n");
out->Indent();
for (int i = 0; i < service->method_count(); i++) {
grpc::string method_name = grpc_generator::LowercaseFirstLetter(
service->method(i)->name());
+ out->Print(GetNodeComments(service->method(i), true).c_str());
out->Print("$method_name$: ",
"method_name", method_name);
PrintMethod(service->method(i), out);
out->Print(",\n");
+ out->Print(GetNodeComments(service->method(i), false).c_str());
}
out->Outdent();
out->Print("};\n\n");
out->Print(template_vars, "exports.$name$Client = "
"grpc.makeGenericClientConstructor($name$Service);\n");
+ out->Print(GetNodeComments(service, false).c_str());
}
-}
-
-grpc::string GetImports(const FileDescriptor *file) {
- grpc::string output;
- {
- StringOutputStream output_stream(&output);
- Printer out(&output_stream, '$');
-
- if (file->service_count() == 0) {
- return output;
- }
-
- out.Print("// GENERATED CODE -- DO NOT EDIT!\n\n");
+void PrintImports(const FileDescriptor *file, Printer *out) {
+ out->Print("var grpc = require('grpc');\n");
+ if (file->message_type_count() > 0) {
+ grpc::string file_path = GetRelativePath(file->name(),
+ GetJSMessageFilename(
+ file->name()));
+ out->Print("var $module_alias$ = require('$file_path$');\n",
+ "module_alias", ModuleAlias(file->name()),
+ "file_path", file_path);
+ }
- out.Print("'use strict';\n");
+ for (int i = 0; i < file->dependency_count(); i++) {
+ grpc::string file_path = GetRelativePath(
+ file->name(), GetJSMessageFilename(file->dependency(i)->name()));
+ out->Print("var $module_alias$ = require('$file_path$');\n",
+ "module_alias", ModuleAlias(file->dependency(i)->name()),
+ "file_path", file_path);
+ }
+ out->Print("\n");
+}
- out.Print("var grpc = require('grpc');\n");
- if (file->message_type_count() > 0) {
- grpc::string file_path = GetRelativePath(file->name(),
- GetJSMessageFilename(
- file->name()));
- out.Print("var $module_alias$ = require('$file_path$');\n",
- "module_alias", ModuleAlias(file->name()),
- "file_path", file_path);
- }
+void PrintTransformers(const FileDescriptor *file, Printer *out) {
+ map<grpc::string, const Descriptor*> messages = GetAllMessages(file);
+ for (std::map<grpc::string, const Descriptor*>::iterator it =
+ messages.begin();
+ it != messages.end(); it++) {
+ PrintMessageTransformer(it->second, out);
+ }
+ out->Print("\n");
+}
- for (int i = 0; i < file->dependency_count(); i++) {
- grpc::string file_path = GetRelativePath(
- file->name(), GetJSMessageFilename(file->dependency(i)->name()));
- out.Print("var $module_alias$ = require('$file_path$');\n",
- "module_alias", ModuleAlias(file->dependency(i)->name()),
- "file_path", file_path);
- }
- out.Print("\n");
+void PrintServices(const FileDescriptor *file, Printer *out) {
+ for (int i = 0; i < file->service_count(); i++) {
+ PrintService(file->service(i), out);
}
- return output;
}
-grpc::string GetTransformers(const FileDescriptor *file) {
+}
+
+grpc::string GenerateFile(const FileDescriptor *file) {
grpc::string output;
{
StringOutputStream output_stream(&output);
@@ -245,31 +250,23 @@ grpc::string GetTransformers(const FileDescriptor *file) {
if (file->service_count() == 0) {
return output;
}
+ out.Print("// GENERATED CODE -- DO NOT EDIT!\n\n");
- map<grpc::string, const Descriptor*> messages = GetAllMessages(file);
- for (std::map<grpc::string, const Descriptor*>::iterator it =
- messages.begin();
- it != messages.end(); it++) {
- PrintMessageTransformer(it->second, &out);
+ grpc::string leading_comments = GetNodeComments(file, true);
+ if (!leading_comments.empty()) {
+ out.Print("// Original file comments:\n");
+ out.Print(leading_comments.c_str());
}
- out.Print("\n");
- }
- return output;
-}
-grpc::string GetServices(const FileDescriptor *file) {
- grpc::string output;
- {
- StringOutputStream output_stream(&output);
- Printer out(&output_stream, '$');
+ out.Print("'use strict';\n");
- if (file->service_count() == 0) {
- return output;
- }
+ PrintImports(file, &out);
- for (int i = 0; i < file->service_count(); i++) {
- PrintService(file->service(i), &out);
- }
+ PrintTransformers(file, &out);
+
+ PrintServices(file, &out);
+
+ out.Print(GetNodeComments(file, false).c_str());
}
return output;
}
diff --git a/src/compiler/node_generator.h b/src/compiler/node_generator.h
index 249a0d011f..d7765e2d28 100644
--- a/src/compiler/node_generator.h
+++ b/src/compiler/node_generator.h
@@ -38,11 +38,7 @@
namespace grpc_node_generator {
-grpc::string GetImports(const grpc::protobuf::FileDescriptor *file);
-
-grpc::string GetTransformers(const grpc::protobuf::FileDescriptor *file);
-
-grpc::string GetServices(const grpc::protobuf::FileDescriptor *file);
+grpc::string GenerateFile(const grpc::protobuf::FileDescriptor *file);
} // namespace grpc_node_generator
diff --git a/src/compiler/node_generator_helpers.h b/src/compiler/node_generator_helpers.h
index f41a2bcf59..5862772841 100644
--- a/src/compiler/node_generator_helpers.h
+++ b/src/compiler/node_generator_helpers.h
@@ -45,6 +45,13 @@ inline grpc::string GetJSServiceFilename(const grpc::string& filename) {
return grpc_generator::StripProto(filename) + "_grpc_pb.js";
}
+// Get leading or trailing comments in a string. Comment lines start with "// ".
+// Leading detached comments are put in in front of leading comments.
+template <typename DescriptorType>
+inline grpc::string GetNodeComments(const DescriptorType *desc, bool leading) {
+ return grpc_generator::GetPrefixedComments(desc, leading, "//");
+}
+
} // namespace grpc_node_generator
#endif // GRPC_INTERNAL_COMPILER_NODE_GENERATOR_HELPERS_H
diff --git a/src/compiler/node_plugin.cc b/src/compiler/node_plugin.cc
index ac5ced3558..39dfa77b8d 100644
--- a/src/compiler/node_plugin.cc
+++ b/src/compiler/node_plugin.cc
@@ -39,10 +39,8 @@
#include "src/compiler/node_generator.h"
#include "src/compiler/node_generator_helpers.h"
-using grpc_node_generator::GetImports;
+using grpc_node_generator::GenerateFile;
using grpc_node_generator::GetJSServiceFilename;
-using grpc_node_generator::GetServices;
-using grpc_node_generator::GetTransformers;
class NodeGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
public:
@@ -53,9 +51,7 @@ class NodeGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
const grpc::string &parameter,
grpc::protobuf::compiler::GeneratorContext *context,
grpc::string *error) const {
- grpc::string code = GetImports(file) +
- GetTransformers(file) +
- GetServices(file);
+ grpc::string code = GenerateFile(file);
if (code.size() == 0) {
return true;
}
diff --git a/src/node/test/math/math_grpc_pb.js b/src/node/test/math/math_grpc_pb.js
index 083ed66913..17a4bf7243 100644
--- a/src/node/test/math/math_grpc_pb.js
+++ b/src/node/test/math/math_grpc_pb.js
@@ -1,94 +1,135 @@
// GENERATED CODE -- DO NOT EDIT!
+// Original file comments:
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
'use strict';
var grpc = require('grpc');
-var math_pb = require('./math_pb.js');
+var math_math_pb = require('../math/math_pb.js');
function serialize_DivArgs(arg) {
- if (!(arg instanceof math_pb.DivArgs)) {
+ if (!(arg instanceof math_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));
+ return math_math_pb.DivArgs.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_DivReply(arg) {
- if (!(arg instanceof math_pb.DivReply)) {
+ if (!(arg instanceof math_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));
+ return math_math_pb.DivReply.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_FibArgs(arg) {
- if (!(arg instanceof math_pb.FibArgs)) {
+ if (!(arg instanceof math_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));
+ return math_math_pb.FibArgs.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_Num(arg) {
- if (!(arg instanceof math_pb.Num)) {
+ if (!(arg instanceof math_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));
+ return math_math_pb.Num.deserializeBinary(new Uint8Array(buffer_arg));
}
var MathService = exports.MathService = {
+ // Div divides args.dividend by args.divisor and returns the quotient and
+ // remainder.
div: {
path: '/math.Math/Div',
requestStream: false,
responseStream: false,
- requestType: math_pb.DivArgs,
- responseType: math_pb.DivReply,
+ requestType: math_math_pb.DivArgs,
+ responseType: math_math_pb.DivReply,
requestSerialize: serialize_DivArgs,
requestDeserialize: deserialize_DivArgs,
responseSerialize: serialize_DivReply,
responseDeserialize: deserialize_DivReply,
},
+ // DivMany accepts an arbitrary number of division args from the client stream
+ // and sends back the results in the reply stream. The stream continues until
+ // the client closes its end; the server does the same after sending all the
+ // replies. The stream ends immediately if either end aborts.
divMany: {
path: '/math.Math/DivMany',
requestStream: true,
responseStream: true,
- requestType: math_pb.DivArgs,
- responseType: math_pb.DivReply,
+ requestType: math_math_pb.DivArgs,
+ responseType: math_math_pb.DivReply,
requestSerialize: serialize_DivArgs,
requestDeserialize: deserialize_DivArgs,
responseSerialize: serialize_DivReply,
responseDeserialize: deserialize_DivReply,
},
+ // Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib
+ // generates up to limit numbers; otherwise it continues until the call is
+ // canceled. Unlike Fib above, Fib has no final FibReply.
fib: {
path: '/math.Math/Fib',
requestStream: false,
responseStream: true,
- requestType: math_pb.FibArgs,
- responseType: math_pb.Num,
+ requestType: math_math_pb.FibArgs,
+ responseType: math_math_pb.Num,
requestSerialize: serialize_FibArgs,
requestDeserialize: deserialize_FibArgs,
responseSerialize: serialize_Num,
responseDeserialize: deserialize_Num,
},
+ // Sum sums a stream of numbers, returning the final result once the stream
+ // is closed.
sum: {
path: '/math.Math/Sum',
requestStream: true,
responseStream: false,
- requestType: math_pb.Num,
- responseType: math_pb.Num,
+ requestType: math_math_pb.Num,
+ responseType: math_math_pb.Num,
requestSerialize: serialize_Num,
requestDeserialize: deserialize_Num,
responseSerialize: serialize_Num,
diff --git a/src/node/test/math/math_pb.js b/src/node/test/math/math_pb.js
index 3489143bec..ccc05c6e06 100644
--- a/src/node/test/math/math_pb.js
+++ b/src/node/test/math/math_pb.js
@@ -65,7 +65,7 @@ proto.math.DivArgs.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -251,7 +251,7 @@ proto.math.DivReply.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -436,7 +436,7 @@ proto.math.FibArgs.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -595,7 +595,7 @@ proto.math.Num.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};
@@ -754,7 +754,7 @@ proto.math.FibReply.toObject = function(includeInstance, msg) {
};
if (includeInstance) {
- obj.$jspbMessageInstance = msg
+ obj.$jspbMessageInstance = msg;
}
return obj;
};