diff --git a/src/main/java/vn/zalopay/benchmark/core/protobuf/ProtocInvoker.java b/src/main/java/vn/zalopay/benchmark/core/protobuf/ProtocInvoker.java index e168be66..2b0935f1 100644 --- a/src/main/java/vn/zalopay/benchmark/core/protobuf/ProtocInvoker.java +++ b/src/main/java/vn/zalopay/benchmark/core/protobuf/ProtocInvoker.java @@ -31,6 +31,7 @@ public class ProtocInvoker { FileSystems.getDefault().getPathMatcher("glob:**/*.proto"); private static final List PROTO_TEMP_FOLDER_PATHS = new ArrayList<>(); private static final int LARGE_FOLDER_LIMIT = 100; + public static final String DESCRIPTOR_EXTENSION = ".bin"; private final ImmutableList protocIncludePaths; private final Path discoveryRoot; @@ -45,7 +46,13 @@ private ProtocInvoker(Path discoveryRoot, ImmutableList protocIncludePaths /** Creates a new {@link ProtocInvoker} with the supplied configuration. */ public static ProtocInvoker forConfig(String protoDiscoveryRoot, String libFolder) { + Path discoveryRootPath = Paths.get(protoDiscoveryRoot); + + if (isBinDescriptor(discoveryRootPath)) { // no other config needed + return new ProtocInvoker(discoveryRootPath, ImmutableList.of()); + } + if (!discoveryRootPath.isAbsolute()) { discoveryRootPath = Paths.get(FileServer.getFileServer().getBaseDir(), protoDiscoveryRoot); @@ -67,6 +74,10 @@ public static ProtocInvoker forConfig(String protoDiscoveryRoot, String libFolde return new ProtocInvoker(discoveryRootPath, includePaths.build()); } + private static boolean isBinDescriptor(Path path) { + return path.toString().endsWith(DESCRIPTOR_EXTENSION); + } + public static List getTempFolderPathToGenerateProtoFiles() { return PROTO_TEMP_FOLDER_PATHS.stream() .map(path -> path.toAbsolutePath().toString()) @@ -83,6 +94,15 @@ public static void cleanTempFolderForGeneratingProtoc() { * {@link FileDescriptorSet} which describes all the protos. */ public FileDescriptorSet invoke() throws ProtocInvocationException { + + if (isBinDescriptor(discoveryRoot)) { + try { + return FileDescriptorSet.parseFrom(Files.readAllBytes(discoveryRoot)); + } catch (IOException e) { + throw new ProtocInvocationException("Unable to parse the provided descriptor", e); + } + } + Path wellKnownTypesInclude = generateWellKnownTypesInclude(); Path descriptorPath = generateDescriptorPath();