commonlib/src/main/java/com/streamsets/pipeline/lib/util/ProtobufTypeUtil.java
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);
      }
    }
  }
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);
      }
    }
  }
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