Update MethodDescriptorInterface

This commit is contained in:
Stanley Cheung 2020-07-21 15:36:33 -07:00 committed by Stanley Cheung
parent 85f7751e77
commit bcdf3520b0
5 changed files with 74 additions and 32 deletions

View File

@ -222,7 +222,7 @@ class GrpcWebClientBase {
*/
startStream_(request, hostname) {
var methodDescriptor = request.getMethodDescriptor();
var path = hostname + methodDescriptor.name;
var path = hostname + methodDescriptor.getName();
var xhr = this.newXhr_();
xhr.setWithCredentials(this.withCredentials_);
@ -231,7 +231,8 @@ class GrpcWebClientBase {
xhr: xhr,
};
var stream = new GrpcWebClientReadableStream(genericTransportInterface);
stream.setResponseDeserializeFn(methodDescriptor.responseDeserializeFn);
stream.setResponseDeserializeFn(
methodDescriptor.getResponseDeserializeFn());
xhr.headers.addAll(request.getMetadata());
this.processHeaders_(xhr);
@ -241,8 +242,8 @@ class GrpcWebClientBase {
path = GrpcWebClientBase.setCorsOverride_(path, headerObject);
}
var serialized =
methodDescriptor.requestSerializeFn(request.getRequestMessage());
var requestSerializeFn = methodDescriptor.getRequestSerializeFn();
var serialized = requestSerializeFn(request.getRequestMessage());
var payload = this.encodeRequest_(serialized);
if (this.format_ == 'text') {
payload = googCrypt.encodeByteArray(payload);

View File

@ -20,7 +20,7 @@ const {Status} = goog.requireType('grpc.web.Status');
/**
* @constructor
* @final
* @implements {MethodDescriptorInterface}
* @implements {MethodDescriptorInterface<REQUEST, RESPONSE>}
* @template REQUEST, RESPONSE
* @param {string} name
* @param {?MethodType} methodType
@ -72,4 +72,48 @@ MethodDescriptor.prototype.createUnaryResponse = function(
return new UnaryResponseInternal(responseMessage, this, metadata, status);
};
/**
* @override
*/
MethodDescriptor.prototype.getName = function() {
return this.name;
};
/**
* @override
*/
MethodDescriptor.prototype.getMethodType = function() {
return this.methodType;
};
/**
* @override
* @return {function(new: RESPONSE, ...)}
*/
MethodDescriptor.prototype.getResponseMessageCtor = function() {
return this.responseType;
};
/**
* @override
* @return {function(new: REQUEST, ...)}
*/
MethodDescriptor.prototype.getRequestMessageCtor = function() {
return this.requestType;
};
/** @override */
MethodDescriptor.prototype.getResponseDeserializeFn = function() {
return this.responseDeserializeFn;
};
/** @override */
MethodDescriptor.prototype.getRequestSerializeFn = function() {
return this.requestSerializeFn;
};
exports = MethodDescriptor;

View File

@ -20,26 +20,7 @@ const {Status} = goog.requireType('grpc.web.Status');
*/
const MethodDescriptorInterface = function() {};
/** @type {string} */
MethodDescriptorInterface.prototype.name;
/** @type {?MethodType} */
MethodDescriptorInterface.prototype.methodType;
/** @type {function(new: REQUEST, ?Array=)} */
MethodDescriptorInterface.prototype.requestType;
/** @type {function(new: RESPONSE, ?Array=)} */
MethodDescriptorInterface.prototype.responseType;
/** @type {function(REQUEST): ?} */
MethodDescriptorInterface.prototype.requestSerializeFn;
/** @type {function(?): RESPONSE} */
MethodDescriptorInterface.prototype.responseDeserializeFn;
/**
* @template REQUEST, RESPONSE
* @param {REQUEST} requestMessage
* @param {!Metadata=} metadata
* @param {!CallOptions=} callOptions
@ -49,9 +30,7 @@ MethodDescriptorInterface.prototype.createRequest = function(
requestMessage, metadata, callOptions) {};
/**
* @template REQUEST, RESPONSE
* @param {RESPONSE} responseMessage
* @param {!Metadata=} metadata
* @param {?Status=} status
@ -60,4 +39,22 @@ MethodDescriptorInterface.prototype.createRequest = function(
MethodDescriptorInterface.prototype.createUnaryResponse = function(
responseMessage, metadata, status) {};
/** @return {string} */
MethodDescriptorInterface.prototype.getName = function() {};
/** @return {?MethodType} */
MethodDescriptorInterface.prototype.getMethodType = function() {};
/** @return {function(new: RESPONSE, ?Array=)} */
MethodDescriptorInterface.prototype.getResponseMessageCtor = function() {};
/** @return {function(new: REQUEST, ?Array=)} */
MethodDescriptorInterface.prototype.getRequestMessageCtor = function() {};
/** @return {function(?): RESPONSE} */
MethodDescriptorInterface.prototype.getResponseDeserializeFn = function() {};
/** @return {function(REQUEST): ?} */
MethodDescriptorInterface.prototype.getRequestSerializeFn = function() {};
exports = MethodDescriptorInterface;

View File

@ -1,13 +1,13 @@
/**
* @fileoverview A wrapper class that provides all the information that is
* needed to make a gRPC-Web request.
* @fileoverview A templated class that is used to address an individual
* gRPC-Web request instance.
*/
goog.module('grpc.web.Request');
goog.module.declareLegacyNamespace();
const CallOptions = goog.require('grpc.web.CallOptions');
const Metadata = goog.require('grpc.web.Metadata');
const MethodDescriptor = goog.requireType('grpc.web.MethodDescriptor');
const MethodDescriptorInterface = goog.requireType('grpc.web.MethodDescriptorInterface');
/**
* @interface
@ -22,7 +22,7 @@ class Request {
/**
* @export
* @return {!MethodDescriptor<REQUEST, RESPONSE>}
* @return {!MethodDescriptorInterface<REQUEST, RESPONSE>}
*/
getMethodDescriptor() {}

View File

@ -6,7 +6,7 @@ goog.module('grpc.web.UnaryResponse');
goog.module.declareLegacyNamespace();
const Metadata = goog.requireType('grpc.web.Metadata');
const MethodDescriptor = goog.requireType('grpc.web.MethodDescriptor');
const MethodDescriptorInterface = goog.requireType('grpc.web.MethodDescriptorInterface');
const {Status} = goog.requireType('grpc.web.Status');
/**
@ -28,7 +28,7 @@ class UnaryResponse {
/**
* @export
* @return {!MethodDescriptor<REQUEST, RESPONSE>}
* @return {!MethodDescriptorInterface<REQUEST, RESPONSE>}
*/
getMethodDescriptor() {}