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


Java FileDescriptor.buildFrom方法代码示例

本文整理汇总了Java中com.google.protobuf.Descriptors.FileDescriptor.buildFrom方法的典型用法代码示例。如果您正苦于以下问题:Java FileDescriptor.buildFrom方法的具体用法?Java FileDescriptor.buildFrom怎么用?Java FileDescriptor.buildFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protobuf.Descriptors.FileDescriptor的用法示例。


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

示例1: descriptorFromProto

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的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

示例2: loadService

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的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

示例3: viewFileDescriptors

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
@Ignore
@Test
public void viewFileDescriptors() throws Exception {
  final FileDescriptorProto child1 =
      getProtocFileDescriptorProto("nonTreeChild1.proto", false, FieldTypeRefsMode.AS_IS);
  final FileDescriptorProto parent1 =
      getProtocFileDescriptorProto("nonTreeParent1.proto", false, FieldTypeRefsMode.AS_IS);
  final FileDescriptorProto parent2 =
      getProtocFileDescriptorProto("nonTreeParent2.proto", false, FieldTypeRefsMode.AS_IS);

  final FileDescriptor fileParent2 = FileDescriptor.buildFrom(parent2, new FileDescriptor[0]);
  final FileDescriptor fileChild1 =
      FileDescriptor.buildFrom(child1, new FileDescriptor[] {fileParent2});
  final FileDescriptor fileParent1 =
      FileDescriptor.buildFrom(parent1, new FileDescriptor[] {fileChild1});

  log.info(fileParent1.toProto().toString());
  log.info(fileChild1.toProto().toString());
  log.info(fileParent2.toProto().toString());

  log.info("messages: {}", fileParent1.getMessageTypes());
  log.info("messages: {}", fileParent1.getEnumTypes());

  assertThat(fileParent1.findMessageTypeByName("Child1"), nullValue());
  assertThat(fileParent1.findEnumTypeByName("Parent2"), not(nullValue()));
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:27,代码来源:ImportPublicTest1.java

示例4: testUnresolvedNamesPostBuildFileProto

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
@Test
public void testUnresolvedNamesPostBuildFileProto() throws Exception {
  final FileDescriptorProto child1 =
      getProtocFileDescriptorProto("nonTreeChild1.proto", false, FieldTypeRefsMode.AS_IS);
  final FileDescriptorProto child2 =
      getProtocFileDescriptorProto("nonTreeChild2.proto", false, FieldTypeRefsMode.AS_IS);
  final FileDescriptorProto originalParent1 =
      getProtocFileDescriptorProto("nonTreeParent1.proto", false, FieldTypeRefsMode.AS_IS);
  final FileDescriptorProto parent2 =
      getProtocFileDescriptorProto("nonTreeParent2.proto", false, FieldTypeRefsMode.AS_IS);

  final Builder parentBuilder = FileDescriptorProto.newBuilder(originalParent1);
  parentBuilder.getMessageTypeBuilder(0).getFieldBuilder(2).clearType().setTypeName("Child2");
  final FileDescriptorProto parent1 = parentBuilder.build();


  final FileDescriptor fileChild2 = FileDescriptor.buildFrom(child2, new FileDescriptor[0]);
  final FileDescriptor fileParent2 =
      FileDescriptor.buildFrom(parent2, new FileDescriptor[] {fileChild2});
  final FileDescriptor fileChild1 =
      FileDescriptor.buildFrom(child1, new FileDescriptor[] {fileParent2});
  final FileDescriptor fileParent1 =
      FileDescriptor.buildFrom(parent1, new FileDescriptor[] {fileChild1});

  log.info(fileParent1.toProto().toString());
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:27,代码来源:ImportPublicTest1.java

示例5: testUnresolvedNamesAllPostBuildFileProto

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
@Test
public void testUnresolvedNamesAllPostBuildFileProto() throws Exception {
  final FileDescriptorProto child1 =
      getProtocFileDescriptorProto("nonTreeChild1.proto", false, RELATIVE_TO_PARENT);
  final FileDescriptorProto child2 =
      getProtocFileDescriptorProto("nonTreeChild2.proto", false, RELATIVE_TO_PARENT);
  final FileDescriptorProto parent1 =
      getProtocFileDescriptorProto("nonTreeParent1.proto", false, RELATIVE_TO_PARENT);
  final FileDescriptorProto parent2 =
      getProtocFileDescriptorProto("nonTreeParent2.proto", false, RELATIVE_TO_PARENT);

  final FileDescriptor fileChild2 = FileDescriptor.buildFrom(child2, new FileDescriptor[0]);
  final FileDescriptor fileParent2 =
      FileDescriptor.buildFrom(parent2, new FileDescriptor[] {fileChild2});
  final FileDescriptor fileChild1 =
      FileDescriptor.buildFrom(child1, new FileDescriptor[] {fileParent2});
  final FileDescriptor fileParent1 =
      FileDescriptor.buildFrom(parent1, new FileDescriptor[] {fileChild1});

  log.info(fileParent1.toProto().toString());
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:22,代码来源:ImportPublicTest1.java

示例6: testParsed

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
@Test
public final void testParsed() throws Exception {
  try {
    walker.walk(protoParser, tree);
    final FileDescriptorProto.Builder protoBuilder =
        (FileDescriptorProto.Builder) protoParser.getParsed().getProto();
    final FileDescriptor fileDescriptor =
        FileDescriptor.buildFrom(protoBuilder.build(), new FileDescriptor[0]);
    fail(String.format("expected exception type %s with message containg '%s', but got none!",
        exception, exceptionExtra));
  } catch (final Exception e) {
    log.debug("expected exception with message '{}'", e.getMessage());
    assertThat(e, instanceOf(exception));
    assertThat(e.getMessage(), containsString(exceptionExtra));
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:17,代码来源:ProtoFileParserValidationsTest.java

示例7: testTextFormatWithDescriptor

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
@Test
public void testTextFormatWithDescriptor() throws Exception {
  //TestUtil.getAllSet();
  String allSet = TextFormat.printToString(TestUtil.getAllSet());
  final DescriptorProto expectedAllSetProto = TestAllTypes.getDescriptor().toProto();
  String allSetProto = TextFormat.printToString(expectedAllSetProto);
  log.debug("the message: {}", allSet);
  log.debug("the proto: {}", allSetProto);
  
  DynamicMessage.Builder builder = DynamicMessage.newBuilder(DescriptorProto.getDescriptor());
  TextFormat.merge(allSetProto, builder);
  Message actualAllSetProto = builder.build();
  
  assertThat(actualAllSetProto).isEqualTo(expectedAllSetProto);
  
  FieldDescriptor field = FileDescriptorProto.getDescriptor()
      .findFieldByNumber(FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER);
  FileDescriptorProto fileProto = FileDescriptorProto.newBuilder().setName("my file1")
      .addRepeatedField(field, actualAllSetProto)
      .build();
  FileDescriptor fileDescriptor = FileDescriptor.buildFrom(fileProto, new FileDescriptor[0]);
  Descriptor actualAllTypesDescriptor = fileDescriptor.findMessageTypeByName(
      TestAllTypes.getDescriptor().getFullName());
  
  assertThat(actualAllTypesDescriptor, equalTo(TestAllTypes.getDescriptor()));
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:27,代码来源:DescriptorFactoryTest.java

示例8: buildDescriptor

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
private static FileDescriptor buildDescriptor(
    String name,
    Map<String, FileDescriptor> descriptors,
    Map<String, FileDescriptorProto> protos)
    throws DescriptorValidationException {
  FileDescriptor file = descriptors.get(name);
  if (file != null) {
    return file;
  }
  FileDescriptorProto proto = protos.get(name);
  FileDescriptor[] deps = new FileDescriptor[proto.getDependencyCount()];
  for (int i = 0; i < proto.getDependencyCount(); i++) {
    deps[i] = buildDescriptor(proto.getDependency(i), descriptors, protos);
  }
  file = FileDescriptor.buildFrom(proto, deps);
  descriptors.put(name, file);
  return file;
}
 
开发者ID:google,项目名称:closure-templates,代码行数:19,代码来源:SoyProtoTypeProvider.java

示例9: buildRowDataConverter

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
static ProtobufRowDataConverter buildRowDataConverter(HasStorage object,
                                               FileDescriptorProto fileProto) {
    Group group = (Group)object;
    FileDescriptor fileDescriptor;
    try {
        fileDescriptor = FileDescriptor.buildFrom(fileProto, DEPENDENCIES);
    }
    catch (DescriptorValidationException ex) {
        throw new ProtobufBuildException(ex);
    }
    return ProtobufRowDataConverter.forGroup(group, fileDescriptor);
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:13,代码来源:ProtobufStorageDescriptionHelper.java

示例10: buildRowConverter

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
static ProtobufRowConverter buildRowConverter(HasStorage object, FileDescriptorProto fileProto) {
    Group group = (Group) object;
    FileDescriptor fileDescriptor;
    try {
        fileDescriptor = FileDescriptor.buildFrom(fileProto, DEPENDENCIES);
    }
    catch (DescriptorValidationException ex) {
        throw new ProtobufBuildException(ex);
    }
    return ProtobufRowConverter.forGroup(group, fileDescriptor);
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:12,代码来源:ProtobufStorageDescriptionHelper.java

示例11: converter

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
protected ProtobufRowConverter converter(Group g) throws Exception {
    AISToProtobuf a2p = new AISToProtobuf(ProtobufRowFormat.Type.GROUP_MESSAGE);
    a2p.addGroup(g);
    FileDescriptorSet set = a2p.build();
    FileDescriptor gdesc = FileDescriptor.buildFrom(set.getFile(0),
                                                    ProtobufStorageDescriptionHelper.DEPENDENCIES);
    return ProtobufRowConverter.forGroup(g, gdesc);
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:9,代码来源:ProtobufRowConverterTest.java

示例12: converter

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
protected ProtobufRowDataConverter converter(Group g) throws Exception {
    AISToProtobuf a2p = new AISToProtobuf(ProtobufRowFormat.Type.GROUP_MESSAGE);
    a2p.addGroup(g);
    FileDescriptorSet set = a2p.build();
    if (false) {
        new ProtobufDecompiler((Appendable)System.out).decompile(set);
    }
    FileDescriptor gdesc = FileDescriptor.buildFrom(set.getFile(0),
                                                    ProtobufStorageDescriptionHelper.DEPENDENCIES);
    return ProtobufRowDataConverter.forGroup(g, gdesc);
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:12,代码来源:ProtobufRowDataConverterTest.java

示例13: build

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
private FileDescriptor build(final FileDescriptor fileDescriptor) {
  try {
    return FileDescriptor.buildFrom(makeCanonicalProto(fileDescriptor), fileDescriptor
        .getDependencies().toArray(new FileDescriptor[0]));
  } catch (final DescriptorValidationException e) {
    throw new DescriptorValidationRuntimeException(e);
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:9,代码来源:FileDescriptors.java

示例14: getBasicCanonicalFileDescriptor

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
public FileDescriptor getBasicCanonicalFileDescriptor(final boolean forceRebuild) {
  if (!forceRebuild && isCanonical()) {
    return delegate;
  }

  try {
    return FileDescriptor.buildFrom(toCanonicalProto(),
        delegate.getDependencies().toArray(new FileDescriptor[0]));
  } catch (final DescriptorValidationException e) {
    throw new DescriptorValidationRuntimeException(e);
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:13,代码来源:FileDescriptorEx.java

示例15: buildFileDescriptorWithReserializedProto

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
private FileDescriptor buildFileDescriptorWithReserializedProto(final FileDescriptorProto proto,
    final FileDescriptor[] dependencies) {
  try {
    final FileDescriptor fileDescriptor = FileDescriptor.buildFrom(proto, dependencies);
    final ExtensionRegistry registry = buildFullRegistryOf(fileDescriptor);
    FileDescriptor.internalUpdateFileDescriptor(fileDescriptor, registry);
    return fileDescriptor;
  } catch (final DescriptorValidationException e) {
    throw new DescriptorValidationRuntimeException(e);
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:12,代码来源:FileDescriptorEx.java


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