/**
  * Populates a map of protobuf extensions and map with the default values for each message field
  * from a map of file descriptors.
  *
  * @param fileDescriptorMap Map of file descriptors
  * @param typeToExtensionMap Map of extensions to populate
  * @param defaultValueMap Map of default values to populate
  */
 public static void populateDefaultsAndExtensions(
     Map<String, Descriptors.FileDescriptor> fileDescriptorMap,
     Map<String, Set<Descriptors.FieldDescriptor>> typeToExtensionMap,
     Map<String, Object> defaultValueMap) {
   for (Descriptors.FileDescriptor f : fileDescriptorMap.values()) {
     // go over every file descriptor and look for extensions and default values of those
     // extensions
     for (Descriptors.FieldDescriptor fieldDescriptor : f.getExtensions()) {
       String containingType = fieldDescriptor.getContainingType().getFullName();
       Set<Descriptors.FieldDescriptor> fieldDescriptors = typeToExtensionMap.get(containingType);
       if (fieldDescriptors == null) {
         fieldDescriptors = new LinkedHashSet<>();
         typeToExtensionMap.put(containingType, fieldDescriptors);
       }
       fieldDescriptors.add(fieldDescriptor);
       if (fieldDescriptor.hasDefaultValue()) {
         defaultValueMap.put(
             containingType + "." + fieldDescriptor.getName(), fieldDescriptor.getDefaultValue());
       }
     }
     // go over messages within file descriptor and look for all fields and extensions and their
     // defaults
     for (Descriptors.Descriptor d : f.getMessageTypes()) {
       addDefaultsAndExtensions(typeToExtensionMap, defaultValueMap, d);
     }
   }
 }
예제 #2
0
 static {
   java.lang.String[] descriptorData = {
     "\n$src/test/proto/TestDataFormats.proto\032\'"
         + "src/main/proto/BookkeeperProtocol.proto*"
         + "R\n\017AuthMessageType\022\024\n\020SUCCESS_RESPONSE\020\001"
         + "\022\024\n\020FAILURE_RESPONSE\020\002\022\023\n\017PAYLOAD_MESSAG"
         + "E\020\003:4\n\013messageType\022\014.AuthMessage\030\350\007 \001(\0162"
         + "\020.AuthMessageTypeB\037\n\033org.apache.bookkeep"
         + "er.protoH\001"
   };
   com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
         public com.google.protobuf.ExtensionRegistry assignDescriptors(
             com.google.protobuf.Descriptors.FileDescriptor root) {
           descriptor = root;
           return null;
         }
       };
   com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(
       descriptorData,
       new com.google.protobuf.Descriptors.FileDescriptor[] {
         org.apache.bookkeeper.proto.BookkeeperProtocol.getDescriptor(),
       },
       assigner);
   messageType.internalInit(descriptor.getExtensions().get(0));
   org.apache.bookkeeper.proto.BookkeeperProtocol.getDescriptor();
 }