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