Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #198 from xander34/master
Browse files Browse the repository at this point in the history
feat: support for bin descriptors
  • Loading branch information
huynhminhtan authored Dec 10, 2022
2 parents 8f00b43 + 9eea208 commit af88100
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ProtocInvoker {
FileSystems.getDefault().getPathMatcher("glob:**/*.proto");
private static final List<Path> PROTO_TEMP_FOLDER_PATHS = new ArrayList<>();
private static final int LARGE_FOLDER_LIMIT = 100;
public static final String DESCRIPTOR_EXTENSION = ".bin";
private final ImmutableList<Path> protocIncludePaths;
private final Path discoveryRoot;

Expand All @@ -45,7 +46,13 @@ private ProtocInvoker(Path discoveryRoot, ImmutableList<Path> 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);
Expand All @@ -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<String> getTempFolderPathToGenerateProtoFiles() {
return PROTO_TEMP_FOLDER_PATHS.stream()
.map(path -> path.toAbsolutePath().toString())
Expand All @@ -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();
Expand Down

0 comments on commit af88100

Please sign in to comment.