From 492a0f7585cb5af10424fbee717ac3f301439801 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Wed, 18 Sep 2019 10:51:32 -0700 Subject: [PATCH] Fix generated code return type, and remove unused var --- javascript/net/grpc/web/grpc_generator.cc | 48 ++++++++++++----------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/javascript/net/grpc/web/grpc_generator.cc b/javascript/net/grpc/web/grpc_generator.cc index 77bbf22d..7ae96993 100644 --- a/javascript/net/grpc/web/grpc_generator.cc +++ b/javascript/net/grpc/web/grpc_generator.cc @@ -159,6 +159,13 @@ string GetSerializeMethodName(const string& mode_var) { return "serializeBinary"; } +std::string GetSerializeMethodReturnType(const string& mode_var) { + if (mode_var == GetModeVar(Mode::OPJSPB)) { + return "string"; + } + return "!Uint8Array"; +} + string LowercaseFirstLetter(string s) { if (s.empty()) { return s; @@ -1049,11 +1056,16 @@ void PrintMethodDescriptorFile(Printer* printer, "$in_type$,\n"); printer->Print(vars, "$out_type$,\n" - "/** @param {!proto.$in$} request */\n" + "/**\n" + " * @param {!proto.$in$} request\n"); + printer->Print( + (" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n") + .c_str()); + printer->Print(" */\n" "function(request) {\n"); printer->Print( (" return request." + GetSerializeMethodName(vars["mode"]) + "();\n") - .c_str()); + .c_str()); printer->Print("},\n"); printer->Print( vars, ("$out_type$." + GetDeserializeMethodName(vars["mode"])).c_str()); @@ -1095,15 +1107,6 @@ void PrintServiceConstructor(Printer* printer, " * @private @const {string} The hostname\n" " */\n" " this.hostname_ = hostname;\n\n" - " /**\n" - " * @private @const {?Object} The credentials to be used to connect\n" - " * to the server\n" - " */\n" - " this.credentials_ = credentials;\n\n" - " /**\n" - " * @private @const {?Object} Options for the client\n" - " */\n" - " this.options_ = options;\n" "};\n\n\n"); } @@ -1134,15 +1137,6 @@ void PrintPromiseServiceConstructor(Printer* printer, " * @private @const {string} The hostname\n" " */\n" " this.hostname_ = hostname;\n\n" - " /**\n" - " * @private @const {?Object} The credentials to be used to connect\n" - " * to the server\n" - " */\n" - " this.credentials_ = credentials;\n\n" - " /**\n" - " * @private @const {?Object} Options for the client\n" - " */\n" - " this.options_ = options;\n" "};\n\n\n"); } @@ -1165,7 +1159,12 @@ void PrintMethodInfo(Printer* printer, std::map vars) { "$in_type$,\n"); printer->Print(vars, "$out_type$,\n" - "/** @param {!proto.$in$} request */\n" + "/**\n" + " * @param {!proto.$in$} request\n"); + printer->Print( + (" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n") + .c_str()); + printer->Print(" */\n" "function(request) {\n"); printer->Print( (" return request." + GetSerializeMethodName(vars["mode"]) + "();\n") @@ -1192,7 +1191,12 @@ void PrintMethodInfo(Printer* printer, std::map vars) { printer->Print(vars, "$out_type$,\n" - "/** @param {!proto.$in$} request */\n" + "/**\n" + " * @param {!proto.$in$} request\n"); + printer->Print( + (" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n") + .c_str()); + printer->Print(" */\n" "function(request) {\n"); printer->Print( (" return request." + GetSerializeMethodName(vars["mode"]) + "();\n")