本文整理汇总了Java中com.google.protobuf.DescriptorProtos.EnumDescriptorProto类的典型用法代码示例。如果您正苦于以下问题:Java EnumDescriptorProto类的具体用法?Java EnumDescriptorProto怎么用?Java EnumDescriptorProto使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EnumDescriptorProto类属于com.google.protobuf.DescriptorProtos包,在下文中一共展示了EnumDescriptorProto类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEnum
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
/**
* TODO (guptasu): Only needed to create NullValue enum. Check if this can be removed.
* Create the Protobuf.Enum instance from enumDescriptorProto.
*/
private static Enum createEnum(String enumName,
EnumDescriptorProto enumDescriptorProto, String fileName) {
com.google.protobuf.Enum.Builder coreEnumBuilder =
com.google.protobuf.Enum.newBuilder().setName(enumName);
coreEnumBuilder.setSyntax(Syntax.SYNTAX_PROTO3);
for (EnumValueDescriptorProto value : enumDescriptorProto.getValueList()) {
com.google.protobuf.EnumValue.Builder coreEnumValueBuilder =
com.google.protobuf.EnumValue.newBuilder();
coreEnumValueBuilder.setName(value.getName()).setNumber(value.getNumber());
coreEnumBuilder.addEnumvalue(coreEnumValueBuilder.build());
}
coreEnumBuilder.setSourceContext(SourceContext.newBuilder().setFileName(fileName));
return coreEnumBuilder.build();
}
示例2: EnumDescriptor
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
private EnumDescriptor(final EnumDescriptorProto proto,
final FileDescriptor file,
final Descriptor parent,
final int index)
throws DescriptorValidationException {
this.index = index;
this.proto = proto;
fullName = computeFullName(file, parent, proto.getName());
this.file = file;
containingType = parent;
if (proto.getValueCount() == 0) {
// We cannot allow enums with no values because this would mean there
// would be no valid default value for fields of this type.
throw new DescriptorValidationException(this,
"Enums must contain at least one value.");
}
values = new EnumValueDescriptor[proto.getValueCount()];
for (int i = 0; i < proto.getValueCount(); i++) {
values[i] = new EnumValueDescriptor(
proto.getValue(i), file, this, i);
}
file.pool.addSymbol(this);
}
示例3: testPackedEnumField
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的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]);
}
示例4: getFullName
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的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();
}
}
示例5: appendToFullName
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的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();
}
}
示例6: EnumDescriptor
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
private EnumDescriptor (final EnumDescriptorProto proto,
final FileDescriptor file,
final Descriptor parent,
final int index)
throws DescriptorValidationException {
this.index = index;
this.proto = proto;
fullName = computeFullName (file, parent, proto.getName ());
this.file = file;
containingType = parent;
if (proto.getValueCount () == 0) {
// We cannot allow enums with no values because this would mean there
// would be no valid default value for fields of this type.
throw new DescriptorValidationException (this,
"Enums must contain at least one value.");
}
values = new EnumValueDescriptor[proto.getValueCount ()];
for (int i = 0; i < proto.getValueCount (); i++) {
values[i] = new EnumValueDescriptor (
proto.getValue (i), file, this, i);
}
file.pool.addSymbol (this);
}
示例7: buildAllOptions
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的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);
}
}
示例8: hasConflictingClassName
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
/** Used by the other overload, descends recursively into messages. */
private static boolean hasConflictingClassName(DescriptorProto messageDesc, String name) {
if (name.equals(messageDesc.getName())) {
return true;
}
for (EnumDescriptorProto enumDesc : messageDesc.getEnumTypeList()) {
if (name.equals(enumDesc.getName())) {
return true;
}
}
for (DescriptorProto nestedMessageDesc : messageDesc.getNestedTypeList()) {
if (hasConflictingClassName(nestedMessageDesc, name)) {
return true;
}
}
return false;
}
示例9: doPrint
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
private void doPrint(FileDescriptorProto fdp, String javaPackage, String outerClassName) {
List<DescriptorProto> messageDescList = Lists.newArrayList(fdp.getMessageTypeList());
List<ServiceDescriptorProto> serviceDescList = Lists.newArrayList(fdp.getServiceList());
List<EnumDescriptorProto> enumDescList = Lists.newArrayList(fdp.getEnumTypeList());
messageDescList.stream().filter(temp -> temp.getEnumTypeList() != null)
.forEach(temp -> enumDescList.addAll(temp.getEnumTypeList()));
printEnum(enumDescList, javaPackage, outerClassName);
printMessage(messageDescList, javaPackage, outerClassName);
printService(serviceDescList, javaPackage);
}
示例10: printEnum
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
private void printEnum(List<EnumDescriptorProto> enumDescList, String javaPackage,
String outerClassName) {
for (EnumDescriptorProto enumDesc : enumDescList) {
String enumClassType = enumDesc.getName();
String enumPackageName = javaPackage + "." + outerClassName;
String fullpojoType = enumPackageName.toLowerCase() + "." + enumClassType;
pojoTypes.put(enumClassType, fullpojoType);
PrintEnumFile enumFile = new PrintEnumFile(generatePath, enumPackageName, enumClassType);
try {
enumFile.setEnumFields(enumDesc.getValueList());
} finally {
enumFile.print();
}
}
}
示例11: generateEnum
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
private EnumDescriptorProto generateEnum(Enum e) {
EnumDescriptorProto.Builder builder = EnumDescriptorProto.newBuilder();
builder.setName(getSimpleName(e.getName()));
for (EnumValue value : e.getEnumvalueList()) {
EnumValueDescriptorProto.Builder valueBuilder = EnumValueDescriptorProto.newBuilder();
valueBuilder.setName(value.getName());
valueBuilder.setNumber(value.getNumber());
valueBuilder.setOptions(generateEnumValueOptions(value));
builder.addValue(valueBuilder.build());
}
builder.setOptions(generateEnumOptions(e));
return builder.build();
}
示例12: EnumType
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
private EnumType(ProtoContainerElement parent, EnumDescriptorProto proto, String path) {
super(parent, proto.getName(), path);
this.proto = proto;
// Build values.
ImmutableList.Builder<EnumValue> valuesBuilder = ImmutableList.builder();
List<EnumValueDescriptorProto> valueProtos = proto.getValueList();
for (int i = 0; i < valueProtos.size(); i++) {
EnumValueDescriptorProto value = valueProtos.get(i);
String childPath = buildPath(path, EnumDescriptorProto.VALUE_FIELD_NUMBER, i);
valuesBuilder.add(EnumValue.create(this, value, childPath));
}
values = valuesBuilder.build();
}
示例13: accept
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
@Accepts
protected void accept(EnumDescriptorProto.Builder enumType) {
pushParent(BuilderVisitorNodeInfo.create(enumType, currentFile));
visitRepeated(EnumDescriptorProto.VALUE_FIELD_NUMBER);
visit(enumType.getOptionsBuilder());
popExpectedParent(enumType);
}
示例14: setProto
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
/** See {@link FileDescriptor#setProto}. */
private void setProto(final EnumDescriptorProto proto) {
this.proto = proto;
for (int i = 0; i < values.length; i++) {
values[i].setProto(proto.getValue(i));
}
}
示例15: decompile
import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; //导入依赖的package包/类
protected void decompile(EnumDescriptorProto enumDescriptor) throws IOException {
indentedFormat("enum %s {", enumDescriptor.getName());
indent++;
if (enumDescriptor.hasOptions()) {
decompileOptions(enumDescriptor.getOptions());
}
for (EnumValueDescriptorProto value : enumDescriptor.getValueList()) {
indentedFormat("%s = %d%s;", value.getName(), value.getNumber(),
value.hasOptions() ? bracketedOptions(value.getOptions()) : "");
}
indent--;
indentedFormat("}");
}