Java Code Examples for com.google.protobuf.Descriptors.FileDescriptor#getDependencies()
The following examples show how to use
com.google.protobuf.Descriptors.FileDescriptor#getDependencies() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtoReflectionService.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
private ServerReflectionResponse createServerReflectionResponse( ServerReflectionRequest request, FileDescriptor fd) { FileDescriptorResponse.Builder fdRBuilder = FileDescriptorResponse.newBuilder(); Set<String> seenFiles = new HashSet<String>(); Queue<FileDescriptor> frontier = new ArrayDeque<FileDescriptor>(); seenFiles.add(fd.getName()); frontier.add(fd); while (!frontier.isEmpty()) { FileDescriptor nextFd = frontier.remove(); fdRBuilder.addFileDescriptorProto(nextFd.toProto().toByteString()); for (FileDescriptor dependencyFd : nextFd.getDependencies()) { if (!seenFiles.contains(dependencyFd.getName())) { seenFiles.add(dependencyFd.getName()); frontier.add(dependencyFd); } } } return ServerReflectionResponse.newBuilder() .setValidHost(request.getHost()) .setOriginalRequest(request) .setFileDescriptorResponse(fdRBuilder) .build(); }
Example 2
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 6 votes |
static Set<FileDescriptor> extractDependencies(List<FileDescriptor> fileDescriptors) { LinkedList<FileDescriptor> loop = new LinkedList<>(fileDescriptors); HashSet<FileDescriptor> fileDescriptorSet = new HashSet<>(fileDescriptors); while (!loop.isEmpty()) { FileDescriptor fileDescriptor = loop.pop(); for (FileDescriptor dependency : fileDescriptor.getDependencies()) { if (!fileDescriptorSet.contains(dependency)) { fileDescriptorSet.add(dependency); loop.push(dependency); } } } return ImmutableSet.copyOf(fileDescriptorSet); }
Example 3
Source File: ProtoReflectionService.java From grpc-java with Apache License 2.0 | 6 votes |
private ServerReflectionResponse createServerReflectionResponse( ServerReflectionRequest request, FileDescriptor fd) { FileDescriptorResponse.Builder fdRBuilder = FileDescriptorResponse.newBuilder(); Set<String> seenFiles = new HashSet<>(); Queue<FileDescriptor> frontier = new ArrayDeque<>(); seenFiles.add(fd.getName()); frontier.add(fd); while (!frontier.isEmpty()) { FileDescriptor nextFd = frontier.remove(); fdRBuilder.addFileDescriptorProto(nextFd.toProto().toByteString()); for (FileDescriptor dependencyFd : nextFd.getDependencies()) { if (!seenFiles.contains(dependencyFd.getName())) { seenFiles.add(dependencyFd.getName()); frontier.add(dependencyFd); } } } return ServerReflectionResponse.newBuilder() .setValidHost(request.getHost()) .setOriginalRequest(request) .setFileDescriptorResponse(fdRBuilder) .build(); }
Example 4
Source File: ProtoReflectionService.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
FileDescriptorIndex(List<ServerServiceDefinition> services) { Queue<FileDescriptor> fileDescriptorsToProcess = new ArrayDeque<FileDescriptor>(); Set<String> seenFiles = new HashSet<String>(); for (ServerServiceDefinition service : services) { io.grpc.ServiceDescriptor serviceDescriptor = service.getServiceDescriptor(); if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) { FileDescriptor fileDescriptor = ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor()) .getFileDescriptor(); String serviceName = serviceDescriptor.getName(); checkState( !serviceNames.contains(serviceName), "Service already defined: %s", serviceName); serviceFileDescriptors.add(fileDescriptor); serviceNames.add(serviceName); if (!seenFiles.contains(fileDescriptor.getName())) { seenFiles.add(fileDescriptor.getName()); fileDescriptorsToProcess.add(fileDescriptor); } } } while (!fileDescriptorsToProcess.isEmpty()) { FileDescriptor currentFd = fileDescriptorsToProcess.remove(); processFileDescriptor(currentFd); for (FileDescriptor dependencyFd : currentFd.getDependencies()) { if (!seenFiles.contains(dependencyFd.getName())) { seenFiles.add(dependencyFd.getName()); fileDescriptorsToProcess.add(dependencyFd); } } } }
Example 5
Source File: ProtobufReflectionUtil.java From stateful-functions with Apache License 2.0 | 5 votes |
private static void addDependenciesRecursively( Set<FileDescriptor> visited, FileDescriptor descriptor) { for (FileDescriptor dependency : descriptor.getDependencies()) { if (visited.add(dependency)) { addDependenciesRecursively(visited, dependency.getFile()); } } }
Example 6
Source File: ProtobufReflectionUtil.java From flink-statefun with Apache License 2.0 | 5 votes |
private static void addDependenciesRecursively( Set<FileDescriptor> visited, FileDescriptor descriptor) { for (FileDescriptor dependency : descriptor.getDependencies()) { if (visited.add(dependency)) { addDependenciesRecursively(visited, dependency.getFile()); } } }
Example 7
Source File: ProtoReflectionService.java From grpc-java with Apache License 2.0 | 5 votes |
FileDescriptorIndex(List<ServerServiceDefinition> services) { Queue<FileDescriptor> fileDescriptorsToProcess = new ArrayDeque<>(); Set<String> seenFiles = new HashSet<>(); for (ServerServiceDefinition service : services) { io.grpc.ServiceDescriptor serviceDescriptor = service.getServiceDescriptor(); if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) { FileDescriptor fileDescriptor = ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor()) .getFileDescriptor(); String serviceName = serviceDescriptor.getName(); checkState( !serviceNames.contains(serviceName), "Service already defined: %s", serviceName); serviceFileDescriptors.add(fileDescriptor); serviceNames.add(serviceName); if (!seenFiles.contains(fileDescriptor.getName())) { seenFiles.add(fileDescriptor.getName()); fileDescriptorsToProcess.add(fileDescriptor); } } } while (!fileDescriptorsToProcess.isEmpty()) { FileDescriptor currentFd = fileDescriptorsToProcess.remove(); processFileDescriptor(currentFd); for (FileDescriptor dependencyFd : currentFd.getDependencies()) { if (!seenFiles.contains(dependencyFd.getName())) { seenFiles.add(dependencyFd.getName()); fileDescriptorsToProcess.add(dependencyFd); } } } }