• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FileDescriptorSet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: generateFile

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的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


示例2: main

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
/**
 * 
 * @author liushiming
 * @param args
 * @since JDK 1.8
 */
public static void main(String[] args) {
  CommandProtoc commondProtoc = CommandProtoc.configProtoPath(
      "/Users/liushiming/project/java/saluki/saluki-plugin/saluki-plugin-common/src/test/java/com/quancheng/saluki",
      new File(
          "/Users/liushiming/project/java/saluki/saluki-example/saluki-example-api/target/protoc-dependencies"));
  FileDescriptorSet fileDescriptorSet = commondProtoc.invoke(
      "/Users/liushiming/project/java/saluki/saluki-plugin/saluki-plugin-common/src/test/java/com/quancheng/saluki/saluki_service.proto");
  Map<Integer, UnknownFieldSet.Field> lengthDelimitedList = fileDescriptorSet.getFile(0)
      .getMessageType(0).getField(0).getOptions().getUnknownFields().asMap();
  for (Map.Entry<Integer, UnknownFieldSet.Field> integerFieldEntry : lengthDelimitedList
      .entrySet()) {
    for (ByteString byteString : integerFieldEntry.getValue().getLengthDelimitedList()) {
      System.out.println(integerFieldEntry.getKey() + "--" + byteString.toStringUtf8());

    }
  }
  System.out.println(fileDescriptorSet);
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:25,代码来源:Validator.java


示例3: fromFileDescriptorSet

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的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


示例4: processDependencies

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的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


示例5: listServices

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
/** Lists the GRPC services - filtered by service name (contains) or method name (contains) */
public static void listServices(
    Output output,
    FileDescriptorSet fileDescriptorSet,
    String protoDiscoveryRoot,
    Optional<String> serviceFilter,
    Optional<String> methodFilter,
    Optional<Boolean> withMessage) {

  ServiceResolver serviceResolver = ServiceResolver.fromFileDescriptorSet(fileDescriptorSet);

  // Add white-space before the rendered output
  output.newLine();

  for (ServiceDescriptor descriptor : serviceResolver.listServices()) {
    boolean matchingDescriptor =
        !serviceFilter.isPresent()
        || descriptor.getFullName().toLowerCase().contains(serviceFilter.get().toLowerCase());

    if (matchingDescriptor) {
      listMethods(output, protoDiscoveryRoot, descriptor, methodFilter, withMessage);
    }
  }
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:25,代码来源:ServiceList.java


示例6: loadService

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的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


示例7: create

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
/**
 * Creates a model from a normalized service config, rather than from descriptor and .yaml files.
 */
public static Model create(Service normalizedConfig) {
  FileDescriptorSet regeneratedDescriptor = DescriptorGenerator.generate(normalizedConfig);
  Model model = create(regeneratedDescriptor);

  // Configured with a stripped Service
  Service.Builder builder = normalizedConfig.toBuilder();
  ImmutableList.Builder<Api> strippedApis = ImmutableList.builder();
  for (Api api : normalizedConfig.getApisList()) {
    strippedApis.add(
        Api.newBuilder().setName(api.getName()).setVersion(api.getVersion()).build());
  }
  // NOTE: Documentation may still contain text from the original protos.
  builder.clearEnums();
  builder.clearTypes();
  builder.clearApis();
  builder.addAllApis(strippedApis.build());
  ConfigSource strippedConfig = ConfigSource.newBuilder(builder.build()).build();

  model.setConfigSources(ImmutableList.of(strippedConfig));

  return model;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:26,代码来源:Model.java


示例8: parseFileDescriptors

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
private FileDescriptorSet parseFileDescriptors(
    ToolOptions options, ModelBuildOverrides registry, DiagCollector diagCollector) {
  String fileDescriptor = options.get(ToolOptions.DESCRIPTOR_SET);
  if (!Strings.isNullOrEmpty(fileDescriptor)) {
    try {
      return parseFileAsDescriptorSet(FileWrapper.from(fileDescriptor), registry, diagCollector);
    } catch (IOException ex) {
      diagCollector.addDiag(
          Diag.error(
              SimpleLocation.TOPLEVEL,
              "Cannot read FileDescriptorSet file '%s': %s",
              fileDescriptor,
              ex.getMessage()));
      return null;
    }
  } else {
    return parseFileAsDescriptorSet(
        options.get(ToolOptions.DESCRIPTOR_SET_CONTENTS), registry, diagCollector);
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:21,代码来源:ModelBuilder.java


示例9: parseFileAsDescriptorSet

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
private FileDescriptorSet parseFileAsDescriptorSet(
    FileWrapper inputFile, ModelBuildOverrides registry, DiagCollector diagCollector) {
  ByteString extensionFile = inputFile.getFileContents();
  try {
    return FileDescriptorSet.parseFrom(extensionFile, registry.getPlatformExtensions());
  } catch (InvalidProtocolBufferException e) {

    diagCollector.addDiag(
        Diag.error(
            SimpleLocation.TOPLEVEL,
            "Cannot read file descriptor file '%s': %s",
            inputFile.getFilename(),
            e.getMessage()));
    return null;
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:17,代码来源:ModelBuilder.java


示例10: resolvesWithErrors

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
@Test
public void resolvesWithErrors() {
  // Modify the descriptor injecting some errors.
  FileDescriptorSet.Builder builder = descriptors.toBuilder();
  builder
      .getFileBuilder(0)
      .getMessageTypeBuilder(0)
      .getFieldBuilder(1) // required N n
      .setTypeName("undef_N");
  builder
      .getFileBuilder(0)
      .getMessageTypeBuilder(0)
      .getFieldBuilder(2) // optional E e
      .setTypeName("undef_E");
  Model testApi = Model.create(builder.build());
  testApi.registerProcessor(new Resolver());
  Truth.assertThat(testApi.establishStage(Resolved.KEY)).isFalse();
  Truth.assertThat(testApi.getDiagReporter().getDiagCollector().getErrorCount()).isEqualTo(2);
  assertThat(testApi.getDiagReporter().getDiagCollector().getDiags().get(0).toString())
      .contains("undef_N");
  assertThat(testApi.getDiagReporter().getDiagCollector().getDiags().get(1).toString())
      .contains("undef_E");
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:24,代码来源:ResolverTest.java


示例11: getDocStringsFromFiles

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
@Override
protected Map<String, String> getDocStringsFromFiles(Map<String, byte[]> files) {
    return files.entrySet().stream()
                .flatMap(entry -> {
                    try {
                        FileDescriptorSet descriptors = FileDescriptorSet.parseFrom(entry.getValue());
                        return descriptors.getFileList().stream();
                    } catch (IOException e) {
                        logger.info("Could not parse file at '{}', skipping. " +
                                    "Is the file a protobuf descriptor file?",
                                    entry.getKey());
                        return Stream.empty();
                    }
                })
                .flatMap(f -> parseFile(f).entrySet().stream())
                .collect(toImmutableMap(Entry::getKey, Entry::getValue, (entry, unused) -> entry));
}
 
开发者ID:line,项目名称:armeria,代码行数:18,代码来源:GrpcDocStringExtractor.java


示例12: addDescriptorToFileSet

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
private FileDescriptorSet.Builder addDescriptorToFileSet(FileDescriptorSet.Builder builder, 
    Descriptor descriptor, Set<FileDescriptorProto> fileProtoSet) {
  List<? extends FileDescriptorProtoOrBuilder> fileList = builder.getFileOrBuilderList();
  final FileDescriptor file = descriptor.getFile();
  FileDescriptorProto proto = file.toProto();
  
  if (fileList.contains(proto)) {
    return builder;
  }
  
  builder.addFile(proto);
  
  for (FileDescriptor dependency : file.getDependencies()) {
    proto = dependency.toProto();
    
    if (!fileList.contains(proto)) {
      builder.addFile(proto);
    }
  }
  
  return builder;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:23,代码来源:DescriptorFactoryTest.java


示例13: computeDescriptorProtoIndex

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
/**
 * Returns a map from descriptor proto name as found inside the descriptors to protos.
 */
private static ImmutableMap<String, FileDescriptorProto> computeDescriptorProtoIndex(
    FileDescriptorSet fileDescriptorSet) {
  ImmutableMap.Builder<String, FileDescriptorProto> resultBuilder = ImmutableMap.builder();
  for (FileDescriptorProto descriptorProto : fileDescriptorSet.getFileList()) {
    resultBuilder.put(descriptorProto.getName(), descriptorProto);
  }
  return resultBuilder.build();
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:12,代码来源:ServiceResolver.java


示例14: getFileDescriptorSet

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
/** Invokes protoc and returns a {@link FileDescriptorSet} used for discovery. */
private static FileDescriptorSet getFileDescriptorSet(ProtoConfiguration protoConfig) {
  try {
    return ProtocInvoker.forConfig(protoConfig).invoke();
  } catch (ProtocInvocationException e) {
    throw new RuntimeException("Failed to invoke the protoc binary", e);
  }
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:9,代码来源:Main.java


示例15: lookupService

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
/**
 * Returns a {@link FileDescriptorSet} containing all the transitive dependencies of the supplied
 * service, as provided by the remote server.
 */
public ListenableFuture<FileDescriptorSet> lookupService(String serviceName) {
  LookupServiceHandler rpcHandler = new LookupServiceHandler(serviceName);
  StreamObserver<ServerReflectionRequest> requestStream = ServerReflectionGrpc.newStub(channel)
      .withDeadlineAfter(LOOKUP_RPC_DEADLINE_MS, TimeUnit.MILLISECONDS)
      .serverReflectionInfo(rpcHandler);
  return rpcHandler.start(requestStream);
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:12,代码来源:ServerReflectionClient.java


示例16: start

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
ListenableFuture<FileDescriptorSet> start(
    StreamObserver<ServerReflectionRequest> requestStream) {
  this.requestStream = requestStream;
  requestStream.onNext(requestForSymbol(serviceName));
  ++outstandingRequests;
  return resultFuture;
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:8,代码来源:ServerReflectionClient.java


示例17: generate

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
private FileDescriptorSet generate() {
  FileDescriptorSet.Builder setBuilder = FileDescriptorSet.newBuilder();
  for (Map.Entry<String, FileContents> entry : contentsByFile.entrySet()) {
    FileContents contents = entry.getValue();
    String fileName = entry.getKey();
    if (!contents.apis.isEmpty() || !contents.types.isEmpty() || !contents.enums.isEmpty()) {
      setBuilder.addFile(generateFile(fileName, contents));
    }
  }
  return setBuilder.build();
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:12,代码来源:DescriptorGenerator.java


示例18: setFileDescriptorSet

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
public Builder setFileDescriptorSet(FileDescriptorSet descriptorSet) {
  Preconditions.checkState(this.descriptor == null, "can only add one FileDescriptorSet");
  this.descriptor = descriptorSet;
  for (FileDescriptorProto fileDescriptor : descriptorSet.getFileList()) {
    add(fileDescriptor);
  }
  return this;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:9,代码来源:ExtensionPool.java


示例19: setup

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
/**
 * Builds an {@link Model} object, using the settings from {@link ToolOptions} and functional
 * overrides from {@link ModelBuildOverrides}. If the build fails, will return a 'null' model and
 * a {@link DiagCollector} containing all warnings and errors up to the failure point.
 */
public ModelBuildResult setup(
    ToolOptions options, ModelBuildOverrides registry, String builtDataPath) {

  DiagCollector diagCollector = new BoundedDiagCollector();
  Set<FileWrapper> protoFiles = parseConfigFiles(options, builtDataPath, diagCollector);
  List<String> protoFileNames = Lists.newArrayList();
  for (FileWrapper protoFile : protoFiles) {
    protoFileNames.add(protoFile.getFilename());
  }
  FileDescriptorSet descriptor = parseFileDescriptors(options, registry, diagCollector);
  ExtensionPool userExtensionPool = parseExtensionDescriptor(options, registry, diagCollector);

  if (diagCollector.hasErrors()) {
    return ModelBuildResult.create(null, diagCollector);
  }

  Model model =
      Model.create(
          descriptor,
          protoFileNames,
          new ExperimentsImpl(options.get(ToolOptions.EXPERIMENTS)),
          userExtensionPool,
          diagCollector);
  if (diagCollector.hasErrors()) {
    return ModelBuildResult.create(null, diagCollector);
  }

  registry.registerProcessors(model);

  model.setDataPath(builtDataPath);

  ToolUtil.setupModelConfigs(model, protoFiles);
  if (diagCollector.hasErrors()) {
    return ModelBuildResult.create(null, diagCollector);
  }

  registry.registerAspects(model);
  return ModelBuildResult.create(model, diagCollector);
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:45,代码来源:ModelBuilder.java


示例20: resolvesOkWithPartialNames

import com.google.protobuf.DescriptorProtos.FileDescriptorSet; //导入依赖的package包/类
@Test
public void resolvesOkWithPartialNames() {
  // Modify the descriptor. Protoc generates full names, and
  // we want to check whether we can also deal with partial names.
  FileDescriptorSet.Builder builder = descriptors.toBuilder();
  builder
      .getFileBuilder(0)
      .getMessageTypeBuilder(0)
      .getFieldBuilder(1) // required N n
      .setTypeName("N");
  Model testApi = Model.create(builder.build());
  testApi.registerProcessor(new Resolver());
  Truth.assertThat(testApi.establishStage(Resolved.KEY)).isTrue();
  Truth.assertThat(testApi.getDiagReporter().getDiagCollector().hasErrors()).isFalse();
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:16,代码来源:ResolverTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Instruction21ih类代码示例发布时间:2022-05-22
下一篇:
Java FileDirContext类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap