Code sync from internal code base

This commit is contained in:
Stanley Cheung 2021-01-13 22:20:56 -08:00 committed by Stanley Cheung
parent e88fdc809d
commit 3fc20fbaf5
4 changed files with 20 additions and 7 deletions

View File

@ -28,7 +28,7 @@ goog.module.declareLegacyNamespace();
const ClientReadableStream = goog.require('grpc.web.ClientReadableStream'); const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
const Error = goog.require('grpc.web.Error'); const GrpcWebError = goog.require('grpc.web.Error');
const MethodDescriptor = goog.require('grpc.web.MethodDescriptor'); const MethodDescriptor = goog.require('grpc.web.MethodDescriptor');
const MethodType = goog.require('grpc.web.MethodType'); const MethodType = goog.require('grpc.web.MethodType');
@ -49,7 +49,7 @@ const AbstractClientBase = class {
* @param {!MethodDescriptor<REQUEST, RESPONSE>| * @param {!MethodDescriptor<REQUEST, RESPONSE>|
* !AbstractClientBase.MethodInfo<REQUEST, RESPONSE>} * !AbstractClientBase.MethodInfo<REQUEST, RESPONSE>}
* methodDescriptor Information of this RPC method * methodDescriptor Information of this RPC method
* @param {function(?Error, ?)} * @param {function(?GrpcWebError, ?)}
* callback A callback function which takes (error, RESPONSE or null) * callback A callback function which takes (error, RESPONSE or null)
* @return {!ClientReadableStream<RESPONSE>} * @return {!ClientReadableStream<RESPONSE>}
*/ */
@ -65,7 +65,7 @@ const AbstractClientBase = class {
* @param {!MethodDescriptor<REQUEST, RESPONSE>| * @param {!MethodDescriptor<REQUEST, RESPONSE>|
* !AbstractClientBase.MethodInfo<REQUEST,RESPONSE>} * !AbstractClientBase.MethodInfo<REQUEST,RESPONSE>}
* methodDescriptor Information of this RPC method * methodDescriptor Information of this RPC method
* @return {!IThenable <!RESPONSE>} * @return {!IThenable<RESPONSE>}
* A promise that resolves to the response message * A promise that resolves to the response message
*/ */
thenableCall(method, requestMessage, metadata, methodDescriptor) {} thenableCall(method, requestMessage, metadata, methodDescriptor) {}

View File

@ -582,7 +582,7 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) {
printer->Print(vars, "proto.$current_package_ns$ = {};\n"); printer->Print(vars, "proto.$current_package_ns$ = {};\n");
offset = dotIndex + 1; offset = dotIndex + 1;
dotIndex = package.find(".", offset); dotIndex = package.find('.', offset);
} }
} }
@ -1338,6 +1338,7 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name,
GeneratorContext* context, GeneratorContext* context,
std::map<string, string> vars) { std::map<string, string> vars) {
std::map<string, string> method_descriptors; std::map<string, string> method_descriptors;
bool has_server_streaming = false;
// Print MethodDescriptor files. // Print MethodDescriptor files.
for (int i = 0; i < file->service_count(); ++i) { for (int i = 0; i < file->service_count(); ++i) {
@ -1351,6 +1352,9 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name,
string method_file_name = Lowercase(service->name()) + "_" + string method_file_name = Lowercase(service->name()) + "_" +
Lowercase(method->name()) + Lowercase(method->name()) +
"_methoddescriptor.js"; "_methoddescriptor.js";
if (method->server_streaming()) {
has_server_streaming = true;
}
std::unique_ptr<ZeroCopyOutputStream> output( std::unique_ptr<ZeroCopyOutputStream> output(
context->Open(method_file_name)); context->Open(method_file_name));
Printer printer(output.get(), '$'); Printer printer(output.get(), '$');
@ -1406,8 +1410,9 @@ void PrintMultipleFilesMode(const FileDescriptor* file, string file_name,
printer1.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); printer1.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n");
printer1.Print(vars, "goog.require('grpc.web.Error');\n"); printer1.Print(vars, "goog.require('grpc.web.Error');\n");
printer2.Print(vars, "goog.require('grpc.web.$mode$ClientBase');\n"); printer2.Print(vars, "goog.require('grpc.web.$mode$ClientBase');\n");
if (has_server_streaming) {
printer2.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n"); printer2.Print(vars, "goog.require('grpc.web.ClientReadableStream');\n");
printer2.Print(vars, "goog.require('grpc.web.Error');\n"); }
PrintClosureDependencies(&printer1, file); PrintClosureDependencies(&printer1, file);
PrintClosureDependencies(&printer2, file); PrintClosureDependencies(&printer2, file);

View File

@ -222,7 +222,7 @@ class GrpcWebClientBase {
* @static * @static
* @template RESPONSE * @template RESPONSE
* @param {!ClientReadableStream<RESPONSE>} stream * @param {!ClientReadableStream<RESPONSE>} stream
* @param {function(?Error, ?RESPONSE, ?Status=, ?Metadata=)| * @param {function(?Error, ?RESPONSE, ?Status=, ?Object<string, string>=)|
* function(?Error,?RESPONSE)} callback * function(?Error,?RESPONSE)} callback
* @param {boolean} useUnaryResponse * @param {boolean} useUnaryResponse
*/ */

View File

@ -124,6 +124,14 @@ class GrpcWebStreamParser {
return this.errorMessage_; return this.errorMessage_;
} }
/**
* @override
* @return {boolean}
*/
acceptsBinaryInput() {
return true;
}
/** /**
* Parse the new input. * Parse the new input.
* *