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


Java FieldDescriptorProto.getTypeName方法代码示例

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


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

示例1: createType

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
/**
 * TODO (guptasu): only needed to create hard coded Types (Struct, ListValue, and Value). Check
 * if this can be removed. Create the Protobuf.Type instance from descriptorProto.
 */
private static Type createType(String typeName, DescriptorProto descriptorProto,
    String fileName) {
  Type.Builder coreTypeBuilder = Type.newBuilder().setName(typeName);

  int count = 1;
  for (FieldDescriptorProto fieldProto : descriptorProto.getFieldList()) {
    Field.Kind fieldKind = Field.Kind.valueOf(fieldProto.getType().getNumber());
    Cardinality cardinality = Cardinality.CARDINALITY_OPTIONAL;
    if (fieldProto.getLabel() == Label.LABEL_REPEATED) {
      cardinality = Cardinality.CARDINALITY_REPEATED;
    }
    Field.Builder coreFieldBuilder = Field
        .newBuilder()
        .setName(fieldProto.getName())
        .setNumber(count++)
        .setKind(fieldKind)
        .setCardinality(cardinality);
    if (fieldKind == Kind.TYPE_MESSAGE || fieldKind == Kind.TYPE_ENUM) {
      String typeFullName =
          fieldProto.getTypeName().startsWith(".") ? fieldProto.getTypeName().substring(1)
              : fieldProto.getTypeName();
      coreFieldBuilder.setTypeUrl(TYPE_SERVICE_BASE_URL + typeFullName);
    }
    coreTypeBuilder.addFields(coreFieldBuilder.build());
  }
  coreTypeBuilder.setSourceContext(SourceContext.newBuilder().setFileName(fileName));
  coreTypeBuilder.setSyntax(Syntax.SYNTAX_PROTO3);
  return coreTypeBuilder.build();
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:34,代码来源:TypesBuilderFromDescriptor.java

示例2: decompileFields

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
protected void decompileFields(List<FieldDescriptorProto> fieldDescriptors,
                               Map<String,DescriptorProto> groups)
        throws IOException {
    for (FieldDescriptorProto fieldDescriptor : fieldDescriptors) {
        String label = LABELS.get(fieldDescriptor.getLabel());
        String type = TYPES.get(fieldDescriptor.getType());
        String name = fieldDescriptor.getName();
        if (fieldDescriptor.hasTypeName()) {
            type = fieldDescriptor.getTypeName();
            if ((absolutePackage != null) && type.startsWith(absolutePackage)) {
                type = type.substring(absolutePackage.length());
            }
        }
        DescriptorProto groupDescriptor = null;
        if (fieldDescriptor.getType() == Type.TYPE_GROUP) {
            groupDescriptor = groups.get(type);
            if (groupDescriptor != null) {
                name = type;
                type = "group";
            }
        }
        indentedFormat("%s %s %s = %d",
                       label, type, name, fieldDescriptor.getNumber());
        if (fieldDescriptor.hasOptions() || fieldDescriptor.hasDefaultValue()) {
            write(defaultAndOptions(fieldDescriptor.hasOptions() ? fieldDescriptor.getOptions() : null,
                                    fieldDescriptor.hasDefaultValue() ? fieldDescriptor.getDefaultValue() : null));
        }
        if (groupDescriptor == null) {
            write(";");
        }
        else {
            decompileMessageBody(groupDescriptor);
        }
    }
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:36,代码来源:ProtobufDecompiler.java

示例3: getTypeName

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
static public String getTypeName(FieldDescriptorProto proto) {
    Type t = proto.getType();
    if (t==Type.TYPE_MESSAGE || t==Type.TYPE_ENUM) {
        String name = proto.getTypeName();
        if (name.startsWith(".")) {
            return name.replaceFirst("\\.", "");
        } else {
            return name;
        }
    }
    
    return typeMap.get(t);
}
 
开发者ID:rhlabs,项目名称:louie,代码行数:14,代码来源:ProtoServlet.java


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