当前位置: 首页>>代码示例>>Java>>正文


Java FileDescriptorProto类代码示例

本文整理汇总了Java中com.google.protobuf.DescriptorProtos.FileDescriptorProto的典型用法代码示例。如果您正苦于以下问题:Java FileDescriptorProto类的具体用法?Java FileDescriptorProto怎么用?Java FileDescriptorProto使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileDescriptorProto类属于com.google.protobuf.DescriptorProtos包,在下文中一共展示了FileDescriptorProto类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateFile

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
private FileDescriptorProto generateFile(String name, FileContents contents) {
  FileDescriptorProto.Builder fileBuilder = FileDescriptorProto.newBuilder();
  fileBuilder.setName(name);
  if (!Strings.isNullOrEmpty(contents.packageName)) {
    fileBuilder.setPackage(contents.packageName);
  }
  for (Api api : contents.apis) {
    fileBuilder.addService(generateApi(api));
  }
  for (Type type : contents.types.values()) {
    fileBuilder.addMessageType(generateType(type, contents));
  }
  for (Enum e : contents.enums) {
    fileBuilder.addEnumType(generateEnum(e));
  }
  if (imports.containsKey(name)) {
    for (String imported : imports.get(name)) {
      fileBuilder.addDependency(imported);
    }
  }
  return fileBuilder.build();
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:23,代码来源:DescriptorGenerator.java

示例2: findServices

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
private List<ServiceContext> findServices(List<FileDescriptorProto> protos, ProtoTypeMap typeMap) {
    List<ServiceContext> contexts = new ArrayList<>();

    protos.forEach(fileProto -> {
        List<Location> locations = fileProto.getSourceCodeInfo().getLocationList();
        locations.stream()
                .filter(location -> location.getPathCount() == 2 && location.getPath(0) == FileDescriptorProto.SERVICE_FIELD_NUMBER)
                .forEach(location -> {
                    int serviceNumber = location.getPath(1);
                    ServiceContext serviceContext = buildServiceContext(fileProto.getService(serviceNumber), typeMap, locations, serviceNumber);
                    serviceContext.javaDoc = getJavaDoc(getComments(location), getServiceJavaDocPrefix());
                    serviceContext.protoName = fileProto.getName();
                    serviceContext.packageName = extractPackageName(fileProto);
                    contexts.add(serviceContext);
                });
    });

    return contexts;
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:20,代码来源:ReactiveGrpcGenerator.java

示例3: buildServiceContext

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
private ServiceContext buildServiceContext(ServiceDescriptorProto serviceProto, ProtoTypeMap typeMap, List<Location> locations, int serviceNumber) {
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.fileName = getClassPrefix() + serviceProto.getName() + "Grpc.java";
    serviceContext.className = getClassPrefix() + serviceProto.getName() + "Grpc";
    serviceContext.serviceName = serviceProto.getName();
    serviceContext.deprecated = serviceProto.getOptions() != null && serviceProto.getOptions().getDeprecated();

    locations.stream()
            .filter(location -> location.getPathCount() == METHOD_NUMBER_OF_PATHS &&
                    location.getPath(0) == FileDescriptorProto.SERVICE_FIELD_NUMBER &&
                    location.getPath(1) == serviceNumber &&
                    location.getPath(2) == ServiceDescriptorProto.METHOD_FIELD_NUMBER)
            .forEach(location -> {
                int methodNumber = location.getPath(METHOD_NUMBER_OF_PATHS - 1);
                MethodContext methodContext = buildMethodContext(serviceProto.getMethod(methodNumber), typeMap);
                methodContext.methodNumber = methodNumber;
                methodContext.javaDoc = getJavaDoc(getComments(location), getMethodJavaDocPrefix());
                serviceContext.methods.add(methodContext);
            });
    return serviceContext;
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:22,代码来源:ReactiveGrpcGenerator.java

示例4: generateFile

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
public void generateFile(String protoPath) {
  try {
    if (pojoTypes == null) {
      pojoTypes = Maps.newHashMap();
    }
  } finally {
    if (!new File(protoPath).exists()) {
      logger.warn("protoPath:" + protoPath
          + " not exist, it may be in the third party jars, so it can't be generate");
      return;
    }
    FileDescriptorSet fileDescriptorSet = commondProtoc.invoke(protoPath);
    for (FileDescriptorProto fdp : fileDescriptorSet.getFileList()) {
      Pair<String, String> packageClassName = this.packageClassName(fdp.getOptions());
      if (packageClassName == null) {
        continue;
      }
      ProtocolStringList dependencyList = fdp.getDependencyList();
      for (Iterator<String> it = dependencyList.iterator(); it.hasNext();) {
        String dependencyPath = discoveryRoot + "/" + it.next();
        generateFile(dependencyPath);
      }
      doPrint(fdp, packageClassName.getLeft(), packageClassName.getRight());
    }
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:27,代码来源:CommonProto2Java.java

示例5: fromFileDescriptorSet

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
/** Creates a resolver which searches the supplied {@link FileDescriptorSet}. */
public static ServiceResolver fromFileDescriptorSet(FileDescriptorSet descriptorSet) {
  ImmutableMap<String, FileDescriptorProto> descriptorProtoIndex =
      computeDescriptorProtoIndex(descriptorSet);
  Map<String, FileDescriptor> descriptorCache = new HashMap<>();

  ImmutableList.Builder<FileDescriptor> result = ImmutableList.builder();
  for (FileDescriptorProto descriptorProto : descriptorSet.getFileList()) {
    try {
      result.add(descriptorFromProto(descriptorProto, descriptorProtoIndex, descriptorCache));
    } catch (DescriptorValidationException e) {
      logger.warn("Skipped descriptor " + descriptorProto.getName() + " due to error", e);
      continue;
    }
  }
  return new ServiceResolver(result.build());
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:18,代码来源:ServiceResolver.java

示例6: descriptorFromProto

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
/**
 * Recursively constructs file descriptors for all dependencies of the supplied proto and returns
 * a {@link FileDescriptor} for the supplied proto itself. For maximal efficiency, reuse the
 * descriptorCache argument across calls.
 */
private static FileDescriptor descriptorFromProto(
    FileDescriptorProto descriptorProto,
    ImmutableMap<String, FileDescriptorProto> descriptorProtoIndex,
    Map<String, FileDescriptor> descriptorCache) throws DescriptorValidationException {
  // First, check the cache.
  String descritorName = descriptorProto.getName();
  if (descriptorCache.containsKey(descritorName)) {
    return descriptorCache.get(descritorName);
  }

  // Then, fetch all the required dependencies recursively.
  ImmutableList.Builder<FileDescriptor> dependencies = ImmutableList.builder();
  for (String dependencyName : descriptorProto.getDependencyList()) {
    if (!descriptorProtoIndex.containsKey(dependencyName)) {
      throw new IllegalArgumentException("Could not find dependency: " + dependencyName);
    }
    FileDescriptorProto dependencyProto = descriptorProtoIndex.get(dependencyName);
    dependencies.add(descriptorFromProto(dependencyProto, descriptorProtoIndex, descriptorCache));
  }

  // Finally, construct the actual descriptor.
  FileDescriptor[] empty = new FileDescriptor[0];
  return FileDescriptor.buildFrom(descriptorProto, dependencies.build().toArray(empty));
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:30,代码来源:ServiceResolver.java

示例7: processDependencies

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
private void processDependencies(FileDescriptorProto fileDescriptor) {
  logger.debug("Processing deps of descriptor: " + fileDescriptor.getName());
  fileDescriptor.getDependencyList().forEach(dep -> {
    if (!resolvedDescriptors.containsKey(dep) && !requestedDescriptors.contains(dep)) {
      requestedDescriptors.add(dep);
      ++outstandingRequests;
      requestStream.onNext(requestForDescriptor(dep));
    }
  });

  --outstandingRequests;
  if (outstandingRequests == 0) {
    logger.debug("Retrieved service definition for [{}] by reflection", serviceName);
    resultFuture.set(FileDescriptorSet.newBuilder()
        .addAllFile(resolvedDescriptors.values())
        .build());
    requestStream.onCompleted();
  }
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:20,代码来源:ServerReflectionClient.java

示例8: loadService

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
private void loadService() {

    LOG.info("Load service definition is starting...");
    InputStream in = null;
    FileDescriptorSet descriptorSet;
    try {
      in = ClassHelper.getClassLoader().getResourceAsStream(GrpcConstants.PROTO_DESC_FILENAME);
      descriptorSet = FileDescriptorSet.parseFrom(in);
      for (FileDescriptorProto fdp : descriptorSet.getFileList()) {
        FileDescriptor fd = FileDescriptor.buildFrom(fdp, new FileDescriptor[] {}, true);
        for (com.google.protobuf.Descriptors.ServiceDescriptor service : fd.getServices()) {
          addServiceDenifition(service.getName(),
              fd.getOptions().getJavaPackage() + '.' + service.getFullName());
        }
      }
      LOG.info("Load service denifition is finished, total {} service are found.", services.size());
    } catch (Exception ex) {
      LOG.error("Load service denifition error happened.", ex);
      throw new RuntimeException(ex);

    } finally {
      IOUtils.closeInputStream(in);
    }
  }
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:25,代码来源:GrpcDescriptorServiceDefinitionLoader.java

示例9: add

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
private void add(FileDescriptorProto file) {
  currentFile = file;
  fullNameSegments.push(file.getPackage());
  locationMap = buildLocationMap(file);
  pathSegments.push(FileDescriptorProto.EXTENSION_FIELD_NUMBER);
  add(file.getExtensionList());
  pathSegments.pop();
  pathSegments.push(FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER);
  for (int i = 0; i < file.getMessageTypeCount(); i++) {
    pathSegments.push(i);
    add(file.getMessageType(i));
    pathSegments.pop();
  }
  pathSegments.pop();
  fullNameSegments.pop();
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:17,代码来源:ExtensionPool.java

示例10: getProtoSyntax

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
private static Syntax getProtoSyntax(FileDescriptorProto proto) {
  if (!proto.hasSyntax()) {
    // TODO(user): This can be removed once protoc outputs proto2 when proto2 is being used.
    //     According to [email protected] it would break a lot of tests, so it is currently not done.
    return Syntax.SYNTAX_PROTO2;
  }
  switch (proto.getSyntax()) {
    case "proto2":
      return Syntax.SYNTAX_PROTO2;
    case "proto3":
      return Syntax.SYNTAX_PROTO3;
    default:
      throw new IllegalArgumentException(
          "Illegal proto syntax for file " + proto.getName() + ": " + proto.getSyntax());
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:17,代码来源:ProtoFile.java

示例11: buildFrom

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
/**
 * Construct a {@code FileDescriptor}.
 *
 * @param proto The protocol message form of the FileDescriptor.
 * @param dependencies {@code FileDescriptor}s corresponding to all of
 *                     the file's dependencies.
 * @param allowUnknownDependencies If true, non-exist dependenncies will be
 *           ignored and undefined message types will be replaced with a
 *           placeholder type.
 * @throws DescriptorValidationException {@code proto} is not a valid
 *           descriptor.  This can occur for a number of reasons, e.g.
 *           because a field has an undefined type or because two messages
 *           were defined with the same name.
 */
public static FileDescriptor buildFrom(
    final FileDescriptorProto proto, final FileDescriptor[] dependencies,
    final boolean allowUnknownDependencies)
    throws DescriptorValidationException {
  // Building descriptors involves two steps:  translating and linking.
  // In the translation step (implemented by FileDescriptor's
  // constructor), we build an object tree mirroring the
  // FileDescriptorProto's tree and put all of the descriptors into the
  // DescriptorPool's lookup tables.  In the linking step, we look up all
  // type references in the DescriptorPool, so that, for example, a
  // FieldDescriptor for an embedded message contains a pointer directly
  // to the Descriptor for that message's type.  We also detect undefined
  // types in the linking step.
  final DescriptorPool pool = new DescriptorPool(
      dependencies, allowUnknownDependencies);
  final FileDescriptor result = new FileDescriptor(
      proto, dependencies, pool, allowUnknownDependencies);
  result.crossLink();
  return result;
}
 
开发者ID:yeriomin,项目名称:play-store-api,代码行数:35,代码来源:Descriptors.java

示例12: FileDescriptor

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
/**
 * Create a placeholder FileDescriptor for a message Descriptor.
 */
FileDescriptor(String packageName, Descriptor message)
    throws DescriptorValidationException {
  this.pool = new DescriptorPool(new FileDescriptor[0], true);
  this.proto = FileDescriptorProto.newBuilder()
      .setName(message.getFullName() + ".placeholder.proto")
      .setPackage(packageName).addMessageType(message.toProto()).build();
  this.dependencies = new FileDescriptor[0];
  this.publicDependencies = new FileDescriptor[0];

  messageTypes = new Descriptor[] {message};
  enumTypes = new EnumDescriptor[0];
  services = new ServiceDescriptor[0];
  extensions = new FieldDescriptor[0];

  pool.addPackage(packageName, this);
  pool.addSymbol(message);
}
 
开发者ID:yeriomin,项目名称:play-store-api,代码行数:21,代码来源:Descriptors.java

示例13: setProto

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
/**
 * Replace our {@link FileDescriptorProto} with the given one, which is
 * identical except that it might contain extensions that weren't present
 * in the original.  This method is needed for bootstrapping when a file
 * defines custom options.  The options may be defined in the file itself,
 * so we can't actually parse them until we've constructed the descriptors,
 * but to construct the descriptors we have to have parsed the descriptor
 * protos.  So, we have to parse the descriptor protos a second time after
 * constructing the descriptors.
 */
private void setProto(final FileDescriptorProto proto) {
  this.proto = proto;

  for (int i = 0; i < messageTypes.length; i++) {
    messageTypes[i].setProto(proto.getMessageType(i));
  }

  for (int i = 0; i < enumTypes.length; i++) {
    enumTypes[i].setProto(proto.getEnumType(i));
  }

  for (int i = 0; i < services.length; i++) {
    services[i].setProto(proto.getService(i));
  }

  for (int i = 0; i < extensions.length; i++) {
    extensions[i].setProto(proto.getExtension(i));
  }
}
 
开发者ID:yeriomin,项目名称:play-store-api,代码行数:30,代码来源:Descriptors.java

示例14: decompile

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
public void decompile(FileDescriptorProto fileDescriptor) throws IOException {
    if (fileDescriptor.hasPackage()) {
        indentedFormat("package %s;", fileDescriptor.getPackage());
        absolutePackage = "." + fileDescriptor.getPackage() + ".";
    }
    for (String dependency : fileDescriptor.getDependencyList()) {
        indentedFormat("import \"%s\";", dependency);
    }
    if (fileDescriptor.hasOptions()) {
        decompileOptions(fileDescriptor.getOptions());
    }
    decompileMembers(fileDescriptor.getEnumTypeList(),
                     fileDescriptor.getMessageTypeList(),
                     Collections.<FieldDescriptorProto>emptyList(),
                     Collections.<DescriptorProto.ExtensionRange>emptyList(),
                     fileDescriptor.getExtensionList());
    for (ServiceDescriptorProto serviceDescriptor : fileDescriptor.getServiceList()) {
        decompile(serviceDescriptor);
    }
    newline();
    flush();
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:23,代码来源:ProtobufDecompiler.java

示例15: testDependencyOrder

import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入依赖的package包/类
public void testDependencyOrder() throws Exception {
  FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
      .setName("foo.proto").build();
  FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
      .setName("bar.proto")
      .addDependency("foo.proto")
      .build();
  FileDescriptorProto bazProto = FileDescriptorProto.newBuilder()
      .setName("baz.proto")
      .addDependency("foo.proto")
      .addDependency("bar.proto")
      .addPublicDependency(0)
      .addPublicDependency(1)
      .build();
  FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto,
      new FileDescriptor[0]);
  FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(barProto,
      new FileDescriptor[] {fooFile});
  
  // Items in the FileDescriptor array can be in any order. 
  Descriptors.FileDescriptor.buildFrom(bazProto,
      new FileDescriptor[] {fooFile, barFile});
  Descriptors.FileDescriptor.buildFrom(bazProto,
      new FileDescriptor[] {barFile, fooFile});
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:26,代码来源:DescriptorsTest.java


注:本文中的com.google.protobuf.DescriptorProtos.FileDescriptorProto类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。