com.google.protobuf.DescriptorProtos.MethodDescriptorProto Java Examples

The following examples show how to use com.google.protobuf.DescriptorProtos.MethodDescriptorProto. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProtobufDecompiler.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void decompile(ServiceDescriptorProto serviceDescriptor) throws IOException {
    indentedFormat("service %s {", serviceDescriptor.getName());
    indent++;
    if (serviceDescriptor.hasOptions()) {
        decompileOptions(serviceDescriptor.getOptions());
    }
    for (MethodDescriptorProto methodDescriptor : serviceDescriptor.getMethodList()) {
        indentedFormat("rpc %s (%s) returns (%s)",
                       methodDescriptor.getName(), methodDescriptor.getInputType(), methodDescriptor.getOutputType());
        if (methodDescriptor.hasOptions()) {
            write("{ ");
            indent++;
            decompileOptions(methodDescriptor.getOptions());
            indent--;
            indentedFormat("}");
        }
        else {
            write(";");
        }
    }
    indent--;
    indentedFormat("}");
}
 
Example #2
Source File: Generator.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
private void addSerializationProviderInit(final State state, final TypeSpec.Builder serviceClassBuilder) {
    final CodeBlock.Builder staticInitBlockBuilder = CodeBlock.builder()
            .addStatement("$T builder = new $T()", ProtoBufSerializationProviderBuilder,
                    ProtoBufSerializationProviderBuilder);

    concat(state.serviceProto.getMethodList().stream()
                    .filter(MethodDescriptorProto::hasInputType)
                    .map(MethodDescriptorProto::getInputType),
            state.serviceProto.getMethodList().stream()
                    .filter(MethodDescriptorProto::hasOutputType)
                    .map(MethodDescriptorProto::getOutputType))
            .distinct()
            .map(messageTypesMap::get)
            .forEach(t -> staticInitBlockBuilder.addStatement("$L.registerMessageType($T.class, $T.parser())",
                    builder, t, t));

    staticInitBlockBuilder
            .addStatement("$L = $L.build()", serializationProvider, builder)
            .build();

    serviceClassBuilder
            .addField(GrpcSerializationProvider, serializationProvider, PRIVATE, STATIC, FINAL)
            .addStaticBlock(staticInitBlockBuilder.build());
}
 
Example #3
Source File: DescriptorGenerator.java    From api-compiler with Apache License 2.0 6 votes vote down vote up
private MethodDescriptorProto generateMethod(Method method) {
  MethodDescriptorProto.Builder builder = MethodDescriptorProto.newBuilder();
  builder.setName(method.getName());
  builder.setInputType(getTypeName(method.getRequestTypeUrl()));
  builder.setOutputType(getTypeName(method.getResponseTypeUrl()));
  builder.setOptions(generateMethodOptions(method));
  builder.setClientStreaming(method.getRequestStreaming());
  // protoc set serverStreaming field as false for legacy streaming options,
  // but google.protobuf.Method set the responseStreaming field to true for both new and legacy
  // streaming setup. So we need to distinguish streaming style while generating
  // MethodDescriptorProto.
  // But we cannot distinguish if the new and old styles are both set which should be rare case.
  if (method.getResponseStreaming() && isLegacyStreaming(method)) {
    builder.setServerStreaming(false);
  } else {
    builder.setServerStreaming(method.getResponseStreaming());
  }
  return builder.build();
}
 
Example #4
Source File: PrintServiceFile.java    From saluki with Apache License 2.0 6 votes vote down vote up
private String generateMethod(MethodDescriptorProto method, String inPutType, String outPutType,
    String methodName, String inputValue) {
  String methodStr =
      "public " + outPutType + " " + methodName + "(" + inPutType + " " + inputValue + ");";
  boolean isClientStream = !method.getServerStreaming() && method.getClientStreaming();
  boolean isBidiStream = method.getServerStreaming() && method.getClientStreaming();
  boolean isServerStream = method.getServerStreaming() && !method.getClientStreaming();
  if (isClientStream || isBidiStream) {
    methodStr =
        "public " + inPutType + " " + methodName + "(" + outPutType + " responseObserver);";
  } else if (isServerStream) {
    methodStr = "public void " + methodName + "(" + inPutType + " " + inputValue + ","
        + outPutType + " responseObserver);";
  }
  return methodStr;
}
 
Example #5
Source File: ReactiveGrpcGenerator.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private MethodContext buildMethodContext(MethodDescriptorProto methodProto, ProtoTypeMap typeMap, List<Location> locations, int methodNumber) {
    MethodContext methodContext = new MethodContext();
    methodContext.methodName = lowerCaseFirst(methodProto.getName());
    methodContext.inputType = typeMap.toJavaTypeName(methodProto.getInputType());
    methodContext.outputType = typeMap.toJavaTypeName(methodProto.getOutputType());
    methodContext.deprecated = methodProto.getOptions() != null && methodProto.getOptions().getDeprecated();
    methodContext.isManyInput = methodProto.getClientStreaming();
    methodContext.isManyOutput = methodProto.getServerStreaming();
    methodContext.methodNumber = methodNumber;

    Location methodLocation = locations.stream()
            .filter(location ->
                location.getPathCount() == METHOD_NUMBER_OF_PATHS &&
                    location.getPath(METHOD_NUMBER_OF_PATHS - 1) == methodNumber
            )
            .findFirst()
            .orElseGet(Location::getDefaultInstance);
    methodContext.javaDoc = getJavaDoc(getComments(methodLocation), getMethodJavaDocPrefix());

    if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
        methodContext.reactiveCallsMethodName = "oneToOne";
        methodContext.grpcCallsMethodName = "asyncUnaryCall";
    }
    if (!methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
        methodContext.reactiveCallsMethodName = "oneToMany";
        methodContext.grpcCallsMethodName = "asyncServerStreamingCall";
    }
    if (methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
        methodContext.reactiveCallsMethodName = "manyToOne";
        methodContext.grpcCallsMethodName = "asyncClientStreamingCall";
    }
    if (methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
        methodContext.reactiveCallsMethodName = "manyToMany";
        methodContext.grpcCallsMethodName = "asyncBidiStreamingCall";
    }
    return methodContext;
}
 
Example #6
Source File: Descriptors.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
private MethodDescriptor(final MethodDescriptorProto proto,
                         final FileDescriptor file,
                         final ServiceDescriptor parent,
                         final int index)
                  throws DescriptorValidationException {
  this.index = index;
  this.proto = proto;
  this.file = file;
  service = parent;

  fullName = parent.getFullName() + '.' + proto.getName();

  file.pool.addSymbol(this);
}
 
Example #7
Source File: Method.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private Method(Interface parent, MethodDescriptorProto proto, String path) {
  super(parent, proto.getName(), path);
  this.isDeprecated = proto.getOptions().getDeprecated();
  this.descriptor = new MethodDescriptor(proto);
  this.requestStreaming = proto.getClientStreaming();
  this.responseStreaming = proto.getServerStreaming();
}
 
Example #8
Source File: Interface.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private Interface(ProtoFile parent, ServiceDescriptorProto proto, String path) {
  super(parent, proto.getName(), path);
  this.proto = proto;

  // Build methods.
  ImmutableList.Builder<Method> methodsBuilder = ImmutableList.builder();
  List<MethodDescriptorProto> methodProtos = proto.getMethodList();
  for (int i = 0; i < methodProtos.size(); i++) {
    String childPath = buildPath(path, ServiceDescriptorProto.METHOD_FIELD_NUMBER, i);
    methodsBuilder.add(Method.create(this, methodProtos.get(i), childPath));
  }

  methods = methodsBuilder.build();
}
 
Example #9
Source File: PrintServiceFile.java    From saluki with Apache License 2.0 5 votes vote down vote up
@Override
protected List<String> collectFileData() {
  String className = super.getClassName();
  String packageName = super.getSourcePackageName().toLowerCase();
  List<String> fileData = Lists.newArrayList();
  fileData.add("package " + packageName + ";");
  fileData.add("public interface " + className + "{");
  for (MethodDescriptorProto method : serviceMethods) {
    String outPutType = method.getOutputType();
    String inPutType = method.getInputType();
    String methodName = method.getName();
    inPutType = CommonUtils.findPojoTypeFromCache(inPutType, pojoTypeCache);
    outPutType = CommonUtils.findPojoTypeFromCache(outPutType, pojoTypeCache);
    String stream = generateGrpcStream(method, inPutType, outPutType);
    if (method.getServerStreaming() || method.getClientStreaming()) {
      outPutType = "io.grpc.stub.StreamObserver<" + outPutType + ">";
    }
    String inputValue = CommonUtils.findNotIncludePackageType(inPutType).toLowerCase();
    if (method.getClientStreaming()) {
      inPutType = "io.grpc.stub.StreamObserver<" + inPutType + ">";
    }
    if (stream != null)
      fileData.add(stream);
    String methodStr = generateMethod(method, inPutType, outPutType, methodName, inputValue);
    fileData.add(methodStr);
  }
  fileData.add("}");
  return fileData;
}
 
Example #10
Source File: FileDescriptor.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Override
public String methodPath(final ServiceDescriptorProto serviceProto, final MethodDescriptorProto methodProto) {
    final StringBuilder sb = new StringBuilder(128).append('/');
    if (isNotNullNorEmpty(protoPackageName)) {
        sb.append(protoPackageName).append('.');
    }
    sb.append(serviceProto.getName()).append('/').append(methodProto.getName());
    return sb.toString();
}
 
Example #11
Source File: Generator.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private static ClassName clientCallClass(final MethodDescriptorProto methodProto, final boolean blocking) {
    if (!blocking) {
        return methodProto.getClientStreaming() ?
                (methodProto.getServerStreaming() ? StreamingClientCall : RequestStreamingClientCall) :
                (methodProto.getServerStreaming() ? ResponseStreamingClientCall : ClientCall);
    }

    return methodProto.getClientStreaming() ?
            (methodProto.getServerStreaming() ? BlockingStreamingClientCall : BlockingRequestStreamingClientCall) :
            (methodProto.getServerStreaming() ? BlockingResponseStreamingClientCall : BlockingClientCall);
}
 
Example #12
Source File: Generator.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private static ClassName routeInterfaceClass(final MethodDescriptorProto methodProto, final boolean blocking) {
    return methodProto.getClientStreaming() ?
            (methodProto.getServerStreaming() ? blocking ? BlockingStreamingRoute : StreamingRoute :
                    blocking ? BlockingRequestStreamingRoute : RequestStreamingRoute) :
            (methodProto.getServerStreaming() ? blocking ? BlockingResponseStreamingRoute : ResponseStreamingRoute
                    : blocking ? BlockingRoute : Route);
}
 
Example #13
Source File: Generator.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private void addClientMetadata(final State state, final TypeSpec.Builder serviceClassBuilder) {
    state.clientMetaDatas = new ArrayList<>(state.serviceProto.getMethodCount());

    state.serviceRpcInterfaces.stream().filter(rpcInterface -> !rpcInterface.blocking).forEach(rpcInterface -> {
        MethodDescriptorProto methodProto = rpcInterface.methodProto;
        final String name = context.deconflictJavaTypeName(sanitizeIdentifier(methodProto.getName(), false) +
                Metadata);

        final ClassName metaDataClassName = ClassName.bestGuess(name);
        final TypeSpec classSpec = classBuilder(name)
                .addModifiers(PUBLIC, STATIC, FINAL)
                .superclass(DefaultGrpcClientMetadata)
                .addField(FieldSpec.builder(metaDataClassName, INSTANCE, PUBLIC, STATIC, FINAL)
                        .initializer("new $T()", metaDataClassName)
                        .build())
                .addMethod(constructorBuilder()
                        .addModifiers(PRIVATE)
                        .addStatement("super($T.$L)", rpcInterface.className, RPC_PATH)
                        .build())
                .addMethod(constructorBuilder()
                        .addModifiers(PUBLIC)
                        .addParameter(GrpcExecutionStrategy, strategy, FINAL)
                        .addStatement("super($T.$L, $L)", rpcInterface.className, RPC_PATH, strategy)
                        .build())
                .build();

        state.clientMetaDatas.add(new ClientMetaData(methodProto, metaDataClassName));
        serviceClassBuilder.addType(classSpec);
    });
}
 
Example #14
Source File: Generator.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
private TypeSpec newServiceFromRoutesClassSpec(final ClassName serviceFromRoutesClass,
                                               final List<RpcInterface> rpcInterfaces,
                                               final ClassName serviceClass) {
    final TypeSpec.Builder serviceFromRoutesSpecBuilder = classBuilder(serviceFromRoutesClass)
            .addModifiers(PRIVATE, STATIC, FINAL)
            .addSuperinterface(serviceClass)
            .addField(AsyncCloseable, closeable, PRIVATE, FINAL);

    final MethodSpec.Builder serviceFromRoutesConstructorBuilder = constructorBuilder()
            .addModifiers(PRIVATE)
            .addParameter(AllGrpcRoutes, routes, FINAL)
            .addStatement("$L = $L", closeable, routes);

    rpcInterfaces.stream().filter(rpcInterface -> !rpcInterface.blocking).forEach(rpc -> {
        MethodDescriptorProto methodProto = rpc.methodProto;
        final ClassName inClass = messageTypesMap.get(methodProto.getInputType());
        final ClassName outClass = messageTypesMap.get(methodProto.getOutputType());
        final String routeName = routeName(methodProto);

        serviceFromRoutesSpecBuilder.addField(ParameterizedTypeName.get(routeInterfaceClass(methodProto),
                inClass, outClass), routeName, PRIVATE, FINAL);

        serviceFromRoutesConstructorBuilder.addStatement("$L = $L.$L($T.$L)", routeName, routes,
                routeFactoryMethodName(methodProto), rpc.className, RPC_PATH);

        serviceFromRoutesSpecBuilder.addMethod(newRpcMethodSpec(methodProto, noneOf(NewRpcMethodFlag.class),
                (name, builder) ->
                        builder.addAnnotation(Override.class)
                                .addParameter(GrpcServiceContext, ctx, FINAL)
                                .addStatement("return $L.handle($L, $L)", routeName, ctx, request)));
    });

    serviceFromRoutesSpecBuilder
            .addMethod(serviceFromRoutesConstructorBuilder.build())
            .addMethod(newDelegatingCompletableMethodSpec(closeAsync, closeable))
            .addMethod(newDelegatingCompletableMethodSpec(closeAsyncGracefully, closeable));

    return serviceFromRoutesSpecBuilder.build();
}
 
Example #15
Source File: DescriptorNormalization.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
public static List<Option> getOptions(MethodDescriptorProto descriptor, boolean withDefaults) {
  return toCoreOptions(maybeCombineOptionsWithDefault(withDefaults,
      descriptor.getOptions().getAllFields(), DEFAULT_METHOD_OPTIONS));
}
 
Example #16
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private RpcInterface(final MethodDescriptorProto methodProto, final boolean blocking,
                     final ClassName className) {
    this.methodProto = methodProto;
    this.blocking = blocking;
    this.className = className;
}
 
Example #17
Source File: Descriptors.java    From play-store-api with GNU General Public License v3.0 4 votes vote down vote up
/** See {@link FileDescriptor#setProto}. */
private void setProto(final MethodDescriptorProto proto) {
  this.proto = proto;
}
 
Example #18
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private ClientMetaData(final MethodDescriptorProto methodProto, final ClassName className) {
    this.methodProto = methodProto;
    this.className = className;
}
 
Example #19
Source File: Descriptors.java    From play-store-api with GNU General Public License v3.0 4 votes vote down vote up
/** Convert the descriptor to its protocol message representation. */
@Override
public MethodDescriptorProto toProto() {
  return proto;
}
 
Example #20
Source File: RestAnalyzerTest.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
private void restify(MethodKind httpKind, String simpleName, String template) {
  Model model = Model.create(FileDescriptorSet.getDefaultInstance());

  model.setServiceConfig(
      ConfigSource.newBuilder(Service.getDefaultInstance())
          .setValue(
              Service.getDescriptor().findFieldByNumber(Service.CONFIG_VERSION_FIELD_NUMBER),
              null,
              UInt32Value.newBuilder().setValue(configVersion).build(),
              new SimpleLocation("from test"))
          .build());
  HttpConfigAspect aspect = HttpConfigAspect.create(model);
  ProtoFile file =
      ProtoFile.create(
          model, FileDescriptorProto.getDefaultInstance(), true, ExtensionPool.EMPTY);
  Interface iface = Interface.create(file, ServiceDescriptorProto.getDefaultInstance(), "");
  Method method =
      Method.create(iface, MethodDescriptorProto.newBuilder().setName(simpleName).build(), "");
  RestMethod restMethod;
  ImmutableList<PathSegment> path = parse(model, template);
  if (!model.getDiagReporter().getDiagCollector().getDiags().isEmpty()) {
    restMethod = RestMethod.create(method, RestKind.CUSTOM, "*error*", "*error*", null);
  } else {
    HttpRule httpRule = HttpRule.getDefaultInstance();
    HttpAttribute httpConfig =
        new HttpAttribute(
            httpRule,
            httpKind,
            MessageType.create(file, Empty.getDescriptor().toProto(), "", ExtensionPool.EMPTY),
            path,
            "",
            false,
            ImmutableList.<HttpAttribute>of(),
            false);
    RestAnalyzer analyzer = new RestAnalyzer(aspect);
    restMethod = analyzer.analyzeMethod(method, httpConfig);
  }

  PrintWriter pw = testOutput();
  pw.print(httpKind.toString());
  pw.print(" ");
  pw.print(simpleName);
  pw.print(" ");
  pw.print(template.isEmpty() ? "(empty)" : template);
  pw.println();
  pw.println(Strings.repeat("=", 70));
  pw.printf("Rest Kind:   %s\n", restMethod.getRestKind());
  pw.printf(
      "Version:  %s\n", restMethod.getVersion().isEmpty() ? "(empty)" : restMethod.getVersion());
  pw.printf(
      "Version with default:  %s\n",
      restMethod.getVersionWithDefault().isEmpty()
          ? "(empty)"
          : restMethod.getVersionWithDefault());
  pw.printf(
      "Simple collection:  %s\n",
      restMethod.getRestCollectionName().isEmpty()
          ? "(empty)"
          : restMethod.getSimpleRestCollectionName());
  pw.printf(
      "Versioned collection:  %s\n",
      restMethod.getRestCollectionName().isEmpty()
      ? "(empty)" : restMethod.getRestCollectionName());
   pw.printf("Base collection:  %s\n",
      restMethod.getBaseRestCollectionName().isEmpty()
      ? "(empty)" : restMethod.getBaseRestCollectionName());
  pw.printf("Custom Name: %s\n",
      restMethod.getRestKind() == RestKind.CUSTOM
      ? restMethod.getRestMethodName() : "(null)");

  List<Diag> diags = model.getDiagReporter().getDiagCollector().getDiags();
  if (diags.size() > 0) {
    pw.println("Diagnostics:");
    for (Diag d : diags) {
      pw.printf("  %s\n", DiagUtils.getDiagToPrint(d, true));
    }
  }
  pw.println();
}
 
Example #21
Source File: BuilderVisitor.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
@Accepts
protected void accept(MethodDescriptorProto.Builder method) {
  pushParent(BuilderVisitorNodeInfo.create(method, currentFile));
  visit(method.getOptionsBuilder());
  popExpectedParent(method);
}
 
Example #22
Source File: Method.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
private MethodDescriptor(MethodDescriptorProto methodProto) {
  this.inputTypeName = methodProto.getInputType();
  this.outputTypeName = methodProto.getOutputType();
  this.optionFields = ImmutableMap.copyOf(methodProto.getOptions().getAllFields());
  this.methodProto = methodProto;
}
 
Example #23
Source File: Method.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a method with {@link MethodDescriptorProto}.
 */
public static Method create(Interface parent, MethodDescriptorProto proto, String path) {
  return new Method(parent, proto, path);
}
 
Example #24
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private MethodSpec newRpcMethodSpec(final MethodDescriptorProto methodProto, final EnumSet<NewRpcMethodFlag> flags,
                                    final BiFunction<String, MethodSpec.Builder, MethodSpec.Builder>
                                            methodBuilderCustomizer) {

    final ClassName inClass = messageTypesMap.get(methodProto.getInputType());
    final ClassName outClass = messageTypesMap.get(methodProto.getOutputType());

    final String name = routeName(methodProto);

    final MethodSpec.Builder methodSpecBuilder = methodBuilderCustomizer.apply(name, methodBuilder(name))
            .addModifiers(PUBLIC);

    final Modifier[] mods = flags.contains(INTERFACE) ? new Modifier[0] : new Modifier[]{FINAL};

    if (flags.contains(BLOCKING)) {
        methodSpecBuilder.addException(Exception.class);

        if (methodProto.getClientStreaming()) {
            if (flags.contains(CLIENT)) {
                methodSpecBuilder.addParameter(ParameterizedTypeName.get(ClassName.get(Iterable.class),
                        inClass), request, mods);
            } else {
                methodSpecBuilder.addParameter(ParameterizedTypeName.get(BlockingIterable, inClass), request,
                        mods);
            }
        } else {
            methodSpecBuilder.addParameter(inClass, request, mods);
        }

        if (methodProto.getServerStreaming()) {
            if (flags.contains(CLIENT)) {
                methodSpecBuilder.returns(ParameterizedTypeName.get(BlockingIterable, outClass));
            } else {
                methodSpecBuilder.addParameter(ParameterizedTypeName.get(GrpcPayloadWriter, outClass),
                        "responseWriter", mods);
            }
        } else {
            methodSpecBuilder.returns(outClass);
        }
    } else {
        if (methodProto.getClientStreaming()) {
            methodSpecBuilder.addParameter(ParameterizedTypeName.get(Publisher, inClass), request, mods);
        } else {
            methodSpecBuilder.addParameter(inClass, request, mods);
        }

        if (methodProto.getServerStreaming()) {
            methodSpecBuilder.returns(ParameterizedTypeName.get(Publisher, outClass));
        } else {
            methodSpecBuilder.returns(ParameterizedTypeName.get(Single, outClass));
        }
    }

    return methodSpecBuilder.build();
}
 
Example #25
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private static String addRouteMethodName(final MethodDescriptorProto methodProto, final boolean blocking) {
    return "add" + (blocking ? Blocking : "") + streamingNameModifier(methodProto) + "Route";
}
 
Example #26
Source File: DescriptorNormalization.java    From api-compiler with Apache License 2.0 4 votes vote down vote up
public static List<Option> getOptions(MethodDescriptorProto descriptor) {
  return getOptions(descriptor, true);
}
 
Example #27
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private static String routeName(final MethodDescriptorProto methodProto) {
    return sanitizeIdentifier(methodProto.getName(), true);
}
 
Example #28
Source File: Generator.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private static ClassName routeInterfaceClass(final MethodDescriptorProto methodProto) {
    return methodProto.getClientStreaming() ?
            (methodProto.getServerStreaming() ? StreamingRoute : RequestStreamingRoute) :
            (methodProto.getServerStreaming() ? ResponseStreamingRoute : Route);
}
 
Example #29
Source File: PrintServiceFile.java    From saluki with Apache License 2.0 4 votes vote down vote up
public void setServiceMethods(List<MethodDescriptorProto> serviceMethods) {
  this.serviceMethods = serviceMethods;
}
 
Example #30
Source File: AbstractGenerator.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
private MethodContext buildMethodContext(MethodDescriptorProto methodProto, ProtoTypeMap typeMap, List<Location> locations,
                                         int methodNumber) {
    MethodContext methodContext = new MethodContext();
    methodContext.setMethodName(lowerCaseFirst(methodProto.getName()));
    methodContext.setInputType(typeMap.toJavaTypeName(methodProto.getInputType()));
    methodContext.setOutputType(typeMap.toJavaTypeName(methodProto.getOutputType()));
    methodContext.setDeprecated(methodProto.getOptions() != null && methodProto.getOptions().getDeprecated());
    methodContext.setManyInput(methodProto.getClientStreaming());
    methodContext.setManyOutput(methodProto.getServerStreaming());
    methodContext.setMethodNumber(methodNumber);

    Optional<Location> found = Optional.empty();
    for (Location location : locations) {
        if (location.getPathCount() == METHOD_NUMBER_OF_PATHS &&
                location.getPath(METHOD_NUMBER_OF_PATHS - 1) == methodNumber) {
            found = Optional.of(location);
            break;
        }
    }
    Location methodLocation = found
            .orElseGet(Location::getDefaultInstance);
    methodContext.setJavaDoc(getJavaDoc(getComments(methodLocation), getMethodJavaDocPrefix()));

    if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
        methodContext.setReactiveCallsMethodName("oneToOne");
        methodContext.setGrpcCallsMethodName("asyncUnaryCall");
    }
    if (!methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
        methodContext.setReactiveCallsMethodName("oneToMany");
        methodContext.setGrpcCallsMethodName("asyncServerStreamingCall");
    }
    if (methodProto.getClientStreaming() && !methodProto.getServerStreaming()) {
        methodContext.setReactiveCallsMethodName("manyToOne");
        methodContext.setGrpcCallsMethodName("asyncClientStreamingCall");
    }
    if (methodProto.getClientStreaming() && methodProto.getServerStreaming()) {
        methodContext.setReactiveCallsMethodName("manyToMany");
        methodContext.setGrpcCallsMethodName("asyncBidiStreamingCall");
    }
    return methodContext;
}