// Path: src/main/java/com/hubspot/jackson/datatype/protobuf/ExtensionRegistryWrapper.java
// public class ExtensionRegistryWrapper {
//   private final Function<Descriptor, Set<ExtensionInfo>> extensionFunction;
// 
//   private ExtensionRegistryWrapper() {
//     this.extensionFunction = new Function<Descriptor, Set<ExtensionInfo>>() {
// 
//       @Override
//       public Set<ExtensionInfo> apply(Descriptor descriptor) {
//         return Collections.emptySet();
//       }
//     };
//   }
// 
//   private ExtensionRegistryWrapper(final ExtensionRegistry extensionRegistry) {
//     this.extensionFunction = new Function<Descriptor, Set<ExtensionInfo>>() {
//       private final Map<Descriptor, Set<ExtensionInfo>> extensionCache = new ConcurrentHashMap<>();
// 
//       @Override
//       public Set<ExtensionInfo> apply(Descriptor descriptor) {
//         Set<ExtensionInfo> cached = extensionCache.get(descriptor);
//         if (cached != null) {
//           return cached;
//         }
// 
//         Set<ExtensionInfo> extensions =
//                 extensionRegistry.getAllImmutableExtensionsByExtendedType(descriptor.getFullName());
//         extensionCache.put(descriptor, extensions);
//         return extensions;
//       }
//     };
//   }
// 
//   public static ExtensionRegistryWrapper wrap(ExtensionRegistry extensionRegistry) {
//     return new ExtensionRegistryWrapper(extensionRegistry);
//   }
// 
//   public static ExtensionRegistryWrapper empty() {
//     return new ExtensionRegistryWrapper();
//   }
// 
//   /**
//    * @deprecated use {@link #getExtensionsByDescriptor(Descriptor)}
//    */
//   @Deprecated
//   public List<ExtensionInfo> findExtensionsByDescriptor(Descriptor descriptor) {
//     return new ArrayList<>(getExtensionsByDescriptor(descriptor));
//   }
// 
//   public Set<ExtensionInfo> getExtensionsByDescriptor(Descriptor descriptor) {
//     return extensionFunction.apply(descriptor);
//   }
// 
//   private interface Function<T, V> {
//     V apply(T t);
//   }
// }


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import com.google.protobuf.ByteString;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.ExtensionRegistry.ExtensionInfo;
import com.google.protobuf.Message;
import com.google.protobuf.Message.Builder;
import com.hubspot.jackson.datatype.protobuf.ExtensionRegistryWrapper;
  }

  @SuppressWarnings("unchecked")
  public static <T extends Builder> T createBuilder(Class<T> builderType, ExtensionRegistry extensionRegistry) {
    Class<? extends Message> messageType = (Class<? extends Message>) builderType.getDeclaringClass();
    return (T) create(messageType, extensionRegistry).toBuilder();
  }

  public static <T extends Builder> List<T> createBuilder(Class<T> builderType, int count) {
    return createBuilder(builderType, ExtensionRegistry.getEmptyRegistry(), count);
  }

  public static <T extends Builder> List<T> createBuilder(Class<T> builderType, ExtensionRegistry extensionRegistry, int count) {
    List<T> builders = new ArrayList<>(count);

    for (int i = 0; i < count; i++) {
      builders.add(createBuilder(builderType, extensionRegistry));
    }

    return builders;
  }

  private static class Creator {
    private final Map<Class<? extends Message>, Builder> partiallyBuilt = new HashMap<>();

    private <T extends Message> T create(Class<T> messageType) {
      return create(messageType, ExtensionRegistry.getEmptyRegistry());
    }

    private <T extends Message> T create(Class<T> messageType, ExtensionRegistry extensionRegistry) {
// Path: src/main/java/com/hubspot/jackson/datatype/protobuf/ExtensionRegistryWrapper.java
// public class ExtensionRegistryWrapper {
//   private final Function<Descriptor, Set<ExtensionInfo>> extensionFunction;
// 
//   private ExtensionRegistryWrapper() {
//     this.extensionFunction = new Function<Descriptor, Set<ExtensionInfo>>() {
// 
//       @Override
//       public Set<ExtensionInfo> apply(Descriptor descriptor) {
//         return Collections.emptySet();
//       }
//     };
//   }
// 
//   private ExtensionRegistryWrapper(final ExtensionRegistry extensionRegistry) {
//     this.extensionFunction = new Function<Descriptor, Set<ExtensionInfo>>() {
//       private final Map<Descriptor, Set<ExtensionInfo>> extensionCache = new ConcurrentHashMap<>();
// 
//       @Override
//       public Set<ExtensionInfo> apply(Descriptor descriptor) {
//         Set<ExtensionInfo> cached = extensionCache.get(descriptor);
//         if (cached != null) {
//           return cached;
//         }
// 
//         Set<ExtensionInfo> extensions =
//                 extensionRegistry.getAllImmutableExtensionsByExtendedType(descriptor.getFullName());
//         extensionCache.put(descriptor, extensions);
//         return extensions;
//       }
//     };
//   }
// 
//   public static ExtensionRegistryWrapper wrap(ExtensionRegistry extensionRegistry) {
//     return new ExtensionRegistryWrapper(extensionRegistry);
//   }
// 
//   public static ExtensionRegistryWrapper empty() {
//     return new ExtensionRegistryWrapper();
//   }
// 
//   /**
//    * @deprecated use {@link #getExtensionsByDescriptor(Descriptor)}
//    */
//   @Deprecated
//   public List<ExtensionInfo> findExtensionsByDescriptor(Descriptor descriptor) {
//     return new ArrayList<>(getExtensionsByDescriptor(descriptor));
//   }
// 
//   public Set<ExtensionInfo> getExtensionsByDescriptor(Descriptor descriptor) {
//     return extensionFunction.apply(descriptor);
//   }
// 
//   private interface Function<T, V> {
//     V apply(T t);
//   }
// }


// Path: src/test/java/com/hubspot/jackson/datatype/protobuf/util/ProtobufCreator.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import com.google.protobuf.ByteString;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.ExtensionRegistry.ExtensionInfo;
import com.google.protobuf.Message;
import com.google.protobuf.Message.Builder;
import com.hubspot.jackson.datatype.protobuf.ExtensionRegistryWrapper;

  }

  @SuppressWarnings("unchecked")
  public static <T extends Builder> T createBuilder(Class<T> builderType, ExtensionRegistry extensionRegistry) {
    Class<? extends Message> messageType = (Class<? extends Message>) builderType.getDeclaringClass();
    return (T) create(messageType, extensionRegistry).toBuilder();
  }

  public static <T extends Builder> List<T> createBuilder(Class<T> builderType, int count) {
    return createBuilder(builderType, ExtensionRegistry.getEmptyRegistry(), count);
  }

  public static <T extends Builder> List<T> createBuilder(Class<T> builderType, ExtensionRegistry extensionRegistry, int count) {
    List<T> builders = new ArrayList<>(count);

    for (int i = 0; i < count; i++) {
      builders.add(createBuilder(builderType, extensionRegistry));
    }

    return builders;
  }

  private static class Creator {
    private final Map<Class<? extends Message>, Builder> partiallyBuilt = new HashMap<>();

    private <T extends Message> T create(Class<T> messageType) {
      return create(messageType, ExtensionRegistry.getEmptyRegistry());
    }

    private <T extends Message> T create(Class<T> messageType, ExtensionRegistry extensionRegistry) {
      return create(messageType, ExtensionRegistryWrapper.wrap(extensionRegistry));