@@ -109,9 +109,6 @@ private static <ResT, ReqT> Grpc<ReqT, ResT> grpc(Descriptors.FileDescriptor pro
109
109
110
110
Descriptors .ServiceDescriptor svc = proto .findServiceByName (serviceName );
111
111
Descriptors .MethodDescriptor mtd = svc .findMethodByName (methodName );
112
- String pkg = proto .getOptions ().getJavaPackage ();
113
- pkg = "" .equals (pkg ) ? proto .getPackage () : pkg ;
114
- String outerClass = getOuterClass (proto );
115
112
116
113
String path = svc .getFullName () + "/" + methodName ;
117
114
@@ -120,20 +117,28 @@ private static <ResT, ReqT> Grpc<ReqT, ResT> grpc(Descriptors.FileDescriptor pro
120
117
- to load the class
121
118
- to invoke a static method on it
122
119
*/
123
- Class <ReqT > requestType = load (pkg + "." + outerClass + mtd .getInputType (). getName (). replace ( '.' , '$' ));
124
- Class <ResT > responsetype = load (pkg + "." + outerClass + mtd .getOutputType (). getName (). replace ( '.' , '$' ));
120
+ Class <ReqT > requestType = load (getClassName ( mtd .getInputType ()));
121
+ Class <ResT > responsetype = load (getClassName ( mtd .getOutputType ()));
125
122
126
123
MethodDescriptor .Marshaller <ReqT > reqMarshaller = ProtoMarshaller .get (requestType );
127
124
MethodDescriptor .Marshaller <ResT > resMarshaller = ProtoMarshaller .get (responsetype );
128
125
129
126
io .grpc .MethodDescriptor .Builder <ReqT , ResT > grpcDesc = io .grpc .MethodDescriptor .<ReqT , ResT >newBuilder ()
130
127
.setFullMethodName (io .grpc .MethodDescriptor .generateFullMethodName (serviceName , methodName ))
131
- .setType (io . grpc . MethodDescriptor . MethodType . UNARY ).setFullMethodName (path ).setRequestMarshaller (reqMarshaller )
128
+ .setType (getMethodType ( mtd ) ).setFullMethodName (path ).setRequestMarshaller (reqMarshaller )
132
129
.setResponseMarshaller (resMarshaller ).setSampledToLocalTracing (true );
133
130
134
131
return new Grpc <>(grpcDesc .build (), PathMatchers .exact (path ), requestType , responsetype , callHandler );
135
132
}
136
133
134
+ private static String getClassName (Descriptors .Descriptor descriptor ) {
135
+ Descriptors .FileDescriptor fd = descriptor .getFile ();
136
+ String outerClass = getOuterClass (fd );
137
+ String pkg = fd .getOptions ().getJavaPackage ();
138
+ pkg = "" .equals (pkg ) ? fd .getPackage () : pkg ;
139
+ return pkg + "." + outerClass + descriptor .getName ().replace ('.' , '$' );
140
+ }
141
+
137
142
@ SuppressWarnings ("unchecked" )
138
143
private static <T > Class <T > load (String className ) {
139
144
try {
@@ -173,4 +178,17 @@ private static String getOuterClassFromFileName(String name) {
173
178
174
179
return sb .toString ();
175
180
}
181
+
182
+ private static io .grpc .MethodDescriptor .MethodType getMethodType (Descriptors .MethodDescriptor mtd ) {
183
+ if (mtd .isClientStreaming ()) {
184
+ if (mtd .isServerStreaming ()) {
185
+ return MethodDescriptor .MethodType .BIDI_STREAMING ;
186
+ } else {
187
+ return MethodDescriptor .MethodType .CLIENT_STREAMING ;
188
+ }
189
+ } else if (mtd .isServerStreaming ()) {
190
+ return MethodDescriptor .MethodType .SERVER_STREAMING ;
191
+ }
192
+ return MethodDescriptor .MethodType .UNARY ;
193
+ }
176
194
}
0 commit comments