本文整理汇总了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();
}
示例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);
}
}
}
示例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);
}