Java Code Examples for com.google.protobuf.Descriptors.Descriptor#getEnumTypes()

The following examples show how to use com.google.protobuf.Descriptors.Descriptor#getEnumTypes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtoGenerator.java    From fuchsia with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example 2
Source File: DynamicSchema.java    From protobuf-dynamic with Apache License 2.0 5 votes vote down vote up
private void addMessageType(Descriptor msgType, String scope, Set<String> msgDupes, Set<String> enumDupes) {
	String msgTypeNameFull = msgType.getFullName();
	String msgTypeNameShort = (scope == null ? msgType.getName() : scope + "." + msgType.getName());
	
	if (mMsgDescriptorMapFull.containsKey(msgTypeNameFull)) throw new IllegalArgumentException("duplicate name: " + msgTypeNameFull);
	if (mMsgDescriptorMapShort.containsKey(msgTypeNameShort)) msgDupes.add(msgTypeNameShort);
	
	mMsgDescriptorMapFull.put(msgTypeNameFull, msgType);
	mMsgDescriptorMapShort.put(msgTypeNameShort, msgType);
	
	for (Descriptor nestedType : msgType.getNestedTypes()) addMessageType(nestedType, msgTypeNameShort, msgDupes, enumDupes);
	for (EnumDescriptor enumType : msgType.getEnumTypes()) addEnumType(enumType, msgTypeNameShort, enumDupes);
}