Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generated code return type, and remove unused var #635

Merged
merged 1 commit into from
Sep 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions javascript/net/grpc/web/grpc_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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");
}

Expand All @@ -1165,7 +1159,12 @@ void PrintMethodInfo(Printer* printer, std::map<string, string> 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")
Expand All @@ -1192,7 +1191,12 @@ void PrintMethodInfo(Printer* printer, std::map<string, string> 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")
Expand Down