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


Java DescriptorProto类代码示例

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


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

示例1: getMessageJavaType

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
private String getMessageJavaType(String packageName, DescriptorProto sourceMessageDesc,
    FieldDescriptorProto field) {
  String fieldType = CommonUtils.findNotIncludePackageType(field.getTypeName());
  Map<String, Pair<DescriptorProto, List<FieldDescriptorProto>>> nestedFieldType =
      transform(sourceMessageDesc);
  // isMap
  if (nestedFieldType.containsKey(fieldType)) {
    Pair<DescriptorProto, List<FieldDescriptorProto>> nestedFieldPair =
        nestedFieldType.get(fieldType);
    if (nestedFieldPair.getRight().size() == 2) {
      DescriptorProto mapSourceMessageDesc = nestedFieldPair.getLeft();
      List<FieldDescriptorProto> mapFieldList = nestedFieldPair.getRight();
      String nestedJavaType =
          "java.util.Map<" + findJavaType(packageName, mapSourceMessageDesc, mapFieldList.get(0))
              + "," + findJavaType(packageName, mapSourceMessageDesc, mapFieldList.get(1)) + ">";
      return nestedJavaType;
    } else {
      return null;
    }
  } else {
    return CommonUtils.findPojoTypeFromCache(field.getTypeName(), pojoTypeCache);
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:24,代码来源:PrintMessageFile.java

示例2: printMessage

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
private void printMessage(List<DescriptorProto> messageDescList, String javaPackage,
    String outerClassName) {
  for (DescriptorProto messageDesc : messageDescList) {
    String pojoClassType = messageDesc.getName();
    String pojoPackageName = javaPackage + "." + outerClassName;
    String fullpojoType = pojoPackageName.toLowerCase() + "." + pojoClassType;
    pojoTypes.put(pojoClassType, fullpojoType);
    PrintMessageFile messageFile =
        new PrintMessageFile(generatePath, pojoPackageName, pojoClassType);
    try {
      messageFile.setMessageFields(messageDesc.getFieldList());
      messageFile.setPojoTypeCache(pojoTypes);
      messageFile.setSourceMessageDesc(messageDesc);
    } finally {
      messageFile.print();
    }
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:19,代码来源:CommonProto2Java.java

示例3: Descriptor

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
Descriptor(final String fullname) throws DescriptorValidationException {
  String name = fullname;
  String packageName = "";
  int pos = fullname.lastIndexOf('.');
  if (pos != -1) {
    name = fullname.substring(pos + 1);
    packageName = fullname.substring(0, pos);
  }
  this.index = 0;
  this.proto = DescriptorProto.newBuilder().setName(name).addExtensionRange(
      DescriptorProto.ExtensionRange.newBuilder().setStart(1)
      .setEnd(536870912).build()).build();
  this.fullName = fullname;
  this.containingType = null;

  this.nestedTypes = new Descriptor[0];
  this.enumTypes = new EnumDescriptor[0];
  this.fields = new FieldDescriptor[0];
  this.extensions = new FieldDescriptor[0];
  this.oneofs = new OneofDescriptor[0];

  // Create a placeholder FileDescriptor to hold this message.
  this.file = new FileDescriptor(packageName, this);
}
 
开发者ID:yeriomin,项目名称:play-store-api,代码行数:25,代码来源:Descriptors.java

示例4: setProto

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
/** See {@link FileDescriptor#setProto}. */
private void setProto(final DescriptorProto proto) {
  this.proto = proto;

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

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

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

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

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

示例5: decompile

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

示例6: testPackedEnumField

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
public void testPackedEnumField() throws Exception {
  FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
      .setName("foo.proto")
      .addEnumType(EnumDescriptorProto.newBuilder()
        .setName("Enum")
        .addValue(EnumValueDescriptorProto.newBuilder()
          .setName("FOO")
          .setNumber(1)
          .build())
        .build())
      .addMessageType(DescriptorProto.newBuilder()
        .setName("Message")
        .addField(FieldDescriptorProto.newBuilder()
          .setName("foo")
          .setTypeName("Enum")
          .setNumber(1)
          .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
          .setOptions(DescriptorProtos.FieldOptions.newBuilder()
            .setPacked(true)
            .build())
          .build())
        .build())
      .build();
  Descriptors.FileDescriptor.buildFrom(
      fileDescriptorProto, new FileDescriptor[0]);
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:27,代码来源:DescriptorsTest.java

示例7: getFullName

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
private static Optional<String> getFullName(FileDescriptorProto descriptor, List<Integer> path) {
    String fullNameSoFar = descriptor.getPackage();
    switch (path.get(0)) {
        case FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER:
            DescriptorProto message = descriptor.getMessageType(path.get(1));
            return appendMessageToFullName(message, path, fullNameSoFar);
        case FileDescriptorProto.ENUM_TYPE_FIELD_NUMBER:
            EnumDescriptorProto enumDescriptor = descriptor.getEnumType(path.get(1));
            return Optional.of(appendEnumToFullName(enumDescriptor, path, fullNameSoFar));
        case FileDescriptorProto.SERVICE_FIELD_NUMBER:
            ServiceDescriptorProto serviceDescriptor = descriptor.getService(path.get(1));
            fullNameSoFar = appendNameComponent(fullNameSoFar, serviceDescriptor.getName());
            if (path.size() > 2) {
                fullNameSoFar = appendFieldComponent(
                        fullNameSoFar, serviceDescriptor.getMethod(path.get(3)).getName());
            }
            return Optional.of(fullNameSoFar);
        default:
            return Optional.empty();
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:GrpcDocStringExtractor.java

示例8: appendToFullName

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
private static Optional<String> appendToFullName(
        DescriptorProto messageDescriptor, List<Integer> path, String fullNameSoFar) {
    switch (path.get(0)) {
        case DescriptorProto.NESTED_TYPE_FIELD_NUMBER:
            DescriptorProto nestedMessage = messageDescriptor.getNestedType(path.get(1));
            return appendMessageToFullName(nestedMessage, path, fullNameSoFar);
        case DescriptorProto.ENUM_TYPE_FIELD_NUMBER:
            EnumDescriptorProto enumDescriptor = messageDescriptor.getEnumType(path.get(1));
            return Optional.of(appendEnumToFullName(enumDescriptor, path, fullNameSoFar));
        case DescriptorProto.FIELD_FIELD_NUMBER:
            FieldDescriptorProto fieldDescriptor = messageDescriptor.getField(path.get(1));
            return Optional.of(appendFieldComponent(fullNameSoFar, fieldDescriptor.getName()));
        default:
            return Optional.empty();
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:17,代码来源:GrpcDocStringExtractor.java

示例9: Descriptor

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
Descriptor (final String fullname) throws DescriptorValidationException {
    String name = fullname;
    String packageName = "";
    int pos = fullname.lastIndexOf ('.');
    if (pos != -1) {
        name = fullname.substring (pos + 1);
        packageName = fullname.substring (0, pos);
    }
    this.index = 0;
    this.proto = DescriptorProto.newBuilder ().setName (name).addExtensionRange (
            DescriptorProto.ExtensionRange.newBuilder ().setStart (1)
            .setEnd (536870912).build ()).build ();
    this.fullName = fullname;
    this.containingType = null;

    this.nestedTypes = new Descriptor[0];
    this.enumTypes = new EnumDescriptor[0];
    this.fields = new FieldDescriptor[0];
    this.extensions = new FieldDescriptor[0];
    this.oneofs = new OneofDescriptor[0];

    // Create a placeholder FileDescriptor to hold this message.
    this.file = new FileDescriptor (packageName, this);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:25,代码来源:Descriptors.java

示例10: setProto

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
/**
 * See {@link FileDescriptor#setProto}.
 */
private void setProto (final DescriptorProto proto) {
    this.proto = proto;

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

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

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

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

示例11: makeCanonicalProto

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
private FileDescriptorProto makeCanonicalProto(final FileDescriptor fileDescriptor) {
  final FileDescriptorProto.Builder protoBuilder =
      FileDescriptorProto.newBuilder(fileDescriptor.toProto());

  for (final FieldDescriptorProto.Builder field : protoBuilder.getExtensionBuilderList()) {
    makeCanonicalField(field, fileDescriptor.findExtensionByName(field.getName()));
  }

  for (final DescriptorProto.Builder message : protoBuilder.getMessageTypeBuilderList()) {
    makeCanonicalMessage(message, fileDescriptor.findMessageTypeByName(message.getName()));
  }

  // for (EnumDescriptorProto.Builder enumProto :
  // protoBuilder.getEnumTypeBuilderList()) {
  // makeCanonicalEnum(enumProto,
  // fileDescriptor.findEnumTypeByName(enumProto.getName()));
  // }

  for (final ServiceDescriptorProto.Builder serviceProto : protoBuilder.getServiceBuilderList()) {
    makeCanonicalService(serviceProto, fileDescriptor.findServiceByName(serviceProto.getName()));
  }

  // TODO: incorporate options' tree walking into canonicalization to eliminate double walking
  return OptionResolver.newBuilder().setCustomOptionsAsExtensions(false)
      .resolveAllOptionsFor(fileDescriptor, protoBuilder).build();
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:27,代码来源:FileDescriptors.java

示例12: buildAllOptions

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
private void buildAllOptions(final FileDescriptorProto.Builder proto) {
  if (!buildOptions(proto.getOptionsBuilder())) {
    proto.clearOptions();
  }

  for (final FieldDescriptorProto.Builder extensionProto : proto.getExtensionBuilderList()) {
    if (!buildOptions(extensionProto.getOptionsBuilder())) {
      extensionProto.clearOptions();
    }
  }

  for (final EnumDescriptorProto.Builder enumProto : proto.getEnumTypeBuilderList()) {
    buildAllOptions(enumProto);
  }

  for (final ServiceDescriptorProto.Builder serviceProto : proto.getServiceBuilderList()) {
    buildAllOptions(serviceProto);
  }

  for (final DescriptorProto.Builder messageProto : proto.getMessageTypeBuilderList()) {
    buildAllOptions(messageProto);
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:24,代码来源:OptionResolver.java

示例13: makeCanonicalProto

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
private FileDescriptorProto makeCanonicalProto(final FileDescriptor file) {
  final FileDescriptorProto.Builder protoBuilder = FileDescriptorProto.newBuilder(file.toProto());

  for (final FieldDescriptorProto.Builder field : protoBuilder.getExtensionBuilderList()) {
    makeCanonicalField(field, file.findExtensionByName(field.getName()));
  }

  for (final DescriptorProto.Builder message : protoBuilder.getMessageTypeBuilderList()) {
    makeCanonicalMessage(message, file.findMessageTypeByName(message.getName()));
  }

  // for (EnumDescriptorProto.Builder enumProto :
  // protoBuilder.getEnumTypeBuilderList()) {
  // makeCanonicalEnum(enumProto,
  // file.findEnumTypeByName(enumProto.getName()));
  // }

  for (final ServiceDescriptorProto.Builder serviceProto : protoBuilder.getServiceBuilderList()) {
    makeCanonicalService(serviceProto, file.findServiceByName(serviceProto.getName()));
  }

  return OptionResolver.newBuilder().setCustomOptionsAsExtensions(reparseCustomOptions)
      .resolveAllOptionsFor(file, protoBuilder).build();
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:25,代码来源:FileDescriptorEx.java

示例14: makeProtoRefsRelative

import com.google.protobuf.DescriptorProtos.DescriptorProto; //导入依赖的package包/类
@SuppressWarnings("null")
public static FileDescriptorProto.Builder makeProtoRefsRelative(final FileDescriptorProto proto,
    final FieldTypeRefsMode fieldTypeRefsMode) {
  if (fieldTypeRefsMode == FieldTypeRefsMode.AS_IS) {
    return FileDescriptorProto.newBuilder(proto);
  }

  final FileDescriptorProto.Builder protoBuilder = FileDescriptorProto.newBuilder(proto);
  final String packagePath = "." + proto.getPackage();

  for (final FieldDescriptorProto.Builder field : protoBuilder.getExtensionBuilderList()) {
    makeFieldRefsRelative(packagePath, field, fieldTypeRefsMode, packagePath);
  }

  for (final DescriptorProto.Builder message : protoBuilder.getMessageTypeBuilderList()) {
    makeMessageRefsRelative(packagePath, message, fieldTypeRefsMode, packagePath);
  }

  return protoBuilder;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:21,代码来源:Misc.java

示例15: testTextFormatWithDescriptor

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


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