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


Java EnumDescriptor类代码示例

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


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

示例1: getValueForField

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
private Object getValueForField(FieldDescriptor field, Object value, Message.Builder builder) {
  // TODO: handle groups, oneof
  if (field.getType() == FieldDescriptor.Type.MESSAGE) {
    Descriptor fieldTypeDescriptor =
        descriptorMapping.get(getReferenceName(field.getMessageType()));
    return createProtoBuf(
        fieldTypeDescriptor, builder.newBuilderForField(field), (Map<String, Object>) value);
  }

  if (field.getType() == FieldDescriptor.Type.ENUM) {
    EnumDescriptor enumDescriptor =
        enumMapping.get(ProtoToGql.getReferenceName(field.getEnumType()));
    return enumDescriptor.findValueByNumber((int) value);
  }

  return value;
}
 
开发者ID:google,项目名称:rejoiner,代码行数:18,代码来源:GqlInputConverter.java

示例2: build

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
GqlInputConverter build() {
  HashBiMap<String, Descriptor> mapping = HashBiMap.create();
  HashBiMap<String, EnumDescriptor> enumMapping = HashBiMap.create(getEnumMap(enumDescriptors));
  LinkedList<Descriptor> loop = new LinkedList<>(descriptors);

  Set<FileDescriptor> fileDescriptorSet = ProtoRegistry.extractDependencies(fileDescriptors);

  for (FileDescriptor fileDescriptor : fileDescriptorSet) {
    loop.addAll(fileDescriptor.getMessageTypes());
    enumMapping.putAll(getEnumMap(fileDescriptor.getEnumTypes()));
  }

  while (!loop.isEmpty()) {
    Descriptor descriptor = loop.pop();
    if (!mapping.containsKey(descriptor.getFullName())) {
      mapping.put(getReferenceName(descriptor), descriptor);
      loop.addAll(descriptor.getNestedTypes());
      enumMapping.putAll(getEnumMap(descriptor.getEnumTypes()));
    }
  }

  return new GqlInputConverter(
      ImmutableBiMap.copyOf(mapping), ImmutableBiMap.copyOf(enumMapping));
}
 
开发者ID:google,项目名称:rejoiner,代码行数:25,代码来源:GqlInputConverter.java

示例3: parseEnum

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
private EnumValueDescriptor parseEnum(EnumDescriptor enumDescriptor, JsonElement json)
    throws InvalidProtocolBufferException {
  String value = json.getAsString();
  EnumValueDescriptor result = enumDescriptor.findValueByName(value);
  if (result == null) {
    // Try to interpret the value as a number.
    try {
      int numericValue = parseInt32(json);
      if (enumDescriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO3) {
        result = enumDescriptor.findValueByNumberCreatingIfUnknown(numericValue);
      } else {
        result = enumDescriptor.findValueByNumber(numericValue);
      }
    } catch (InvalidProtocolBufferException e) {
      // Fall through. This exception is about invalid int32 value we get from parseInt32() but
      // that's not the exception we want the user to see. Since result == null, we will throw
      // an exception later.
    }

    if (result == null) {
      throw new InvalidProtocolBufferException(
          "Invalid enum value: " + value + " for enum type: " + enumDescriptor.getFullName());
    }
  }
  return result;
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:27,代码来源:JsonFormat.java

示例4: parseEnum

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
/**
 * Parse Enum value {@link EnumValueDescriptor} associated with given {@link EnumDescriptor} from
 * given text if found. Otherwise, throw a {@link ParseException}.
 *
 * <p>The text could be either enum value name or enum value number.
 */
static EnumValueDescriptor parseEnum(EnumDescriptor enumType, String text) {
  EnumValueDescriptor value = null;
  if (lookingAtNumber(text)) {
    int number = parseUInt32(text);
    value = enumType.findValueByNumber(number);
    if (value == null) {
      throw new ParseException(String.format(
          "Enum type '%s' has no value with number %d", enumType.getFullName(), number));
    }
  } else {
    value = enumType.findValueByName(text);
    if (value == null) {
      throw new ParseException(String.format(
          "Enum type '%s' has no value with name '%s'", enumType.getFullName(), text));
    }
  }
  return value;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:25,代码来源:ProtoFieldValueParser.java

示例5: doGetType

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
private SoyType doGetType(String name, SoyTypeRegistry typeRegistry,
    GenericDescriptor descriptor) {
  SoyType type;
  synchronized (lock) {
    type = typeCache.get(name);
    if (type == null) {
      if (descriptor instanceof EnumDescriptor) {
        type = new SoyProtoEnumType((EnumDescriptor) descriptor);
      } else {
        type = new SoyProtoType(typeRegistry, (Descriptor) descriptor, extensions.get(name));
      }
      typeCache.put(name, type);
    }
  }
  return type;
}
 
开发者ID:google,项目名称:closure-templates,代码行数:17,代码来源:SoyProtoTypeProvider.java

示例6: walkDescriptor

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
final void walkDescriptor(GenericDescriptor descriptor) {
  if (!visited.add(descriptor.getFullName())) {
    // skip if we have already seen this descriptor
    return;
  }
  if (descriptor instanceof FileDescriptor) {
    walkFileDescriptor((FileDescriptor) descriptor);
  } else if (descriptor instanceof Descriptor) {
    walkMessageDescriptor((Descriptor) descriptor);
  } else if (descriptor instanceof FieldDescriptor) {
    FieldDescriptor fieldDescriptor = (FieldDescriptor) descriptor;
    if (fieldDescriptor.isExtension()) {
      visitExtensionDescriptor(fieldDescriptor);
    } else {
      visitFieldDescriptor(fieldDescriptor);
    }
  } else if (descriptor instanceof EnumDescriptor) {
    visitEnumDescriptor((EnumDescriptor) descriptor);
  }  // services, etc. not needed thus far so neither gathered nor dispatched
}
 
开发者ID:google,项目名称:closure-templates,代码行数:21,代码来源:DescriptorTreeWalker.java

示例7: generateProtoFromDescriptor

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
private void generateProtoFromDescriptor(Descriptor descriptor,
                                         Appendable out, String indent, Map<Descriptor, Boolean> descriptors)
        throws IOException {
    descriptors.put(descriptor, true);

    out.append(indent + "message " + descriptor.getName() + " {\n");

    for (FieldDescriptor fieldDescriptor : descriptor.getFields()) {
        generateProtoFromDescriptor(fieldDescriptor, out, indent + "    ",
                descriptors);
    }

    for (Descriptor nested : descriptor.getNestedTypes()) {
        generateProtoFromDescriptor(nested, out, indent + "    ",
                descriptors);
    }

    for (EnumDescriptor enumDescriptor : descriptor.getEnumTypes()) {
        generateProtoFromDescriptor(enumDescriptor, out, indent + "    ");
    }

    out.append(indent + "}\n");
}
 
开发者ID:ow2-chameleon,项目名称:fuchsia,代码行数:24,代码来源:ProtoGenerator.java

示例8: testEnumDescriptor

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
public void testEnumDescriptor() throws Exception {
  EnumDescriptor enumType = ForeignEnum.getDescriptor();
  EnumDescriptor nestedType = TestAllTypes.NestedEnum.getDescriptor();

  assertEquals("ForeignEnum", enumType.getName());
  assertEquals("protobuf_unittest.ForeignEnum", enumType.getFullName());
  assertEquals(UnittestProto.getDescriptor(), enumType.getFile());
  assertNull(enumType.getContainingType());
  assertEquals(DescriptorProtos.EnumOptions.getDefaultInstance(),
               enumType.getOptions());

  assertEquals("NestedEnum", nestedType.getName());
  assertEquals("protobuf_unittest.TestAllTypes.NestedEnum",
               nestedType.getFullName());
  assertEquals(UnittestProto.getDescriptor(), nestedType.getFile());
  assertEquals(TestAllTypes.getDescriptor(), nestedType.getContainingType());

  EnumValueDescriptor value = ForeignEnum.FOREIGN_FOO.getValueDescriptor();
  assertEquals(value, enumType.getValues().get(0));
  assertEquals("FOREIGN_FOO", value.getName());
  assertEquals(4, value.getNumber());
  assertEquals(value, enumType.findValueByName("FOREIGN_FOO"));
  assertEquals(value, enumType.findValueByNumber(4));
  assertNull(enumType.findValueByName("NO_SUCH_VALUE"));
  for (int i = 0; i < enumType.getValues().size(); i++) {
    assertEquals(i, enumType.getValues().get(i).getIndex());
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:29,代码来源:DescriptorsTest.java

示例9: convert

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
static GraphQLEnumType convert(EnumDescriptor descriptor) {
  GraphQLEnumType.Builder builder = GraphQLEnumType.newEnum().name(getReferenceName(descriptor));
  for (EnumValueDescriptor value : descriptor.getValues()) {
    builder.value(value.getName());
  }
  return builder.build();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:8,代码来源:ProtoToGql.java

示例10: getEnumMap

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
private static BiMap<String, EnumDescriptor> getEnumMap(Iterable<EnumDescriptor> descriptors) {
  HashBiMap<String, EnumDescriptor> mapping = HashBiMap.create();
  for (EnumDescriptor enumDescriptor : descriptors) {
    mapping.put(ProtoToGql.getReferenceName(enumDescriptor), enumDescriptor);
  }
  return mapping;
}
 
开发者ID:google,项目名称:rejoiner,代码行数:8,代码来源:GqlInputConverter.java

示例11: getMap

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
private static BiMap<String, GraphQLType> getMap(
    List<FileDescriptor> fileDescriptors,
    List<Descriptor> descriptors,
    List<EnumDescriptor> enumDescriptors,
    GraphQLInterfaceType nodeInterface) {
  HashBiMap<String, GraphQLType> mapping = HashBiMap.create(getEnumMap(enumDescriptors));
  LinkedList<Descriptor> loop = new LinkedList<>(descriptors);

  Set<FileDescriptor> fileDescriptorSet = extractDependencies(fileDescriptors);

  for (FileDescriptor fileDescriptor : fileDescriptorSet) {
    loop.addAll(fileDescriptor.getMessageTypes());
    mapping.putAll(getEnumMap(fileDescriptor.getEnumTypes()));
  }

  while (!loop.isEmpty()) {
    Descriptor descriptor = loop.pop();
    if (!mapping.containsKey(descriptor.getFullName())) {
      mapping.put(
          ProtoToGql.getReferenceName(descriptor),
          ProtoToGql.convert(descriptor, nodeInterface));
      GqlInputConverter inputConverter =
          GqlInputConverter.newBuilder().add(descriptor.getFile()).build();
      mapping.put(
          GqlInputConverter.getReferenceName(descriptor),
          inputConverter.getInputType(descriptor));
      loop.addAll(descriptor.getNestedTypes());

      mapping.putAll(getEnumMap(descriptor.getEnumTypes()));
    }
  }
  return ImmutableBiMap.copyOf(mapping);
}
 
开发者ID:google,项目名称:rejoiner,代码行数:34,代码来源:ProtoRegistry.java

示例12: getEnumMap

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
private static BiMap<String, GraphQLType> getEnumMap(Iterable<EnumDescriptor> descriptors) {
  HashBiMap<String, GraphQLType> mapping = HashBiMap.create();
  for (EnumDescriptor enumDescriptor : descriptors) {
    mapping.put(
        ProtoToGql.getReferenceName(enumDescriptor), ProtoToGql.convert(enumDescriptor));
  }
  return mapping;
}
 
开发者ID:google,项目名称:rejoiner,代码行数:9,代码来源:ProtoRegistry.java

示例13: printRepeatedEnum

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
static void printRepeatedEnum(List<Integer> values, JsonGenerator gen, EnumDescriptor descriptor)
    throws IOException {
  int numElements = values.size();
  gen.writeStartArray(numElements);
  for (int i = 0; i < numElements; i++) {
    printEnum(values.get(i), gen, descriptor);
  }
  gen.writeEndArray();
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:10,代码来源:SerializeSupport.java

示例14: printEnum

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
static void printEnum(int value, JsonGenerator gen, EnumDescriptor descriptor)
    throws IOException {
  EnumValueDescriptor valueDescriptor = descriptor.findValueByNumber(value);
  if (valueDescriptor == null) {
    gen.writeNumber(value);
  } else {
    gen.writeString(valueDescriptor.getName());
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:10,代码来源:SerializeSupport.java

示例15: getReferencedEnums

import com.google.protobuf.Descriptors.EnumDescriptor; //导入依赖的package包/类
/**
 * @return the set of all enums referred to be this message and its nested
 *         messages. Enum references are due to message-typed fields.
 */
public List<ProtoEnum> getReferencedEnums() {
  if (referencedEnums == null) {
    referencedEnums = Lists.newArrayList();
    for (EnumDescriptor d : collectEnums(descriptor, Sets.<EnumDescriptor> newLinkedHashSet())) {
      referencedEnums.add(adapt(d));
    }
  }
  return referencedEnums;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:14,代码来源:Message.java


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