use of com.google.protobuf.Descriptors.FileDescriptor in project atlasdb by palantir.
the class ColumnValueDescription method hydrateFileDescriptorTree.
private static FileDescriptor hydrateFileDescriptorTree(FileDescriptorTreeProto proto) throws DescriptorValidationException, InvalidProtocolBufferException {
FileDescriptor[] dependencies = new FileDescriptor[proto.getDependenciesCount()];
for (int i = 0; i < proto.getDependenciesCount(); i++) {
dependencies[i] = hydrateFileDescriptorTree(proto.getDependencies(i));
}
FileDescriptorProto fileProto = FileDescriptorProto.parseFrom(proto.getProtoFileDescriptor());
return FileDescriptor.buildFrom(fileProto, dependencies);
}
use of com.google.protobuf.Descriptors.FileDescriptor in project BIMserver by opensourceBIM.
the class ProtocolBuffersMetaData method load.
public void load(InputStream inputStream) {
try {
FileDescriptorSet descriptorSet = FileDescriptorSet.parseFrom(inputStream);
List<FileDescriptorProto> fileList = descriptorSet.getFileList();
FileDescriptorProto fileDescriptorProto = fileList.get(0);
FileDescriptor[] dependencyDescriptors = getDependencyDescriptors(fileDescriptorProto);
FileDescriptor fileDescriptor = FileDescriptor.buildFrom(fileDescriptorProto, dependencyDescriptors);
loaded.put(fileDescriptor.getName(), fileDescriptor);
fileDescriptor.getMessageTypes().forEach(descriptor -> this.messageDescriptors.put(descriptor.getName(), new MessageDescriptorContainer(descriptor)));
fileDescriptor.getServices().forEach(serviceDescriptor -> this.serviceDescriptors.put(serviceDescriptor.getName(), new ServiceDescriptorContainer(serviceDescriptor)));
} catch (IOException e) {
LOGGER.error("", e);
} catch (DescriptorValidationException e) {
LOGGER.error("", e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
LOGGER.error("", e);
}
}
}
use of com.google.protobuf.Descriptors.FileDescriptor in project grpc-java by grpc.
the class ProtoReflectionService method getRefreshedIndex.
/**
* Retrieves the index for services of the server that dispatches the current call. Computes
* one if not exist. The index is updated if any changes to the server's mutable services are
* detected. A change is any addition or removal in the set of file descriptors attached to the
* mutable services or a change in the service names.
*/
private ServerReflectionIndex getRefreshedIndex() {
synchronized (lock) {
Server server = InternalServer.SERVER_CONTEXT_KEY.get();
ServerReflectionIndex index = serverReflectionIndexes.get(server);
if (index == null) {
index = new ServerReflectionIndex(server.getImmutableServices(), server.getMutableServices());
serverReflectionIndexes.put(server, index);
return index;
}
Set<FileDescriptor> serverFileDescriptors = new HashSet<>();
Set<String> serverServiceNames = new HashSet<>();
List<ServerServiceDefinition> serverMutableServices = server.getMutableServices();
for (ServerServiceDefinition mutableService : serverMutableServices) {
io.grpc.ServiceDescriptor serviceDescriptor = mutableService.getServiceDescriptor();
if (serviceDescriptor.getSchemaDescriptor() instanceof ProtoFileDescriptorSupplier) {
String serviceName = serviceDescriptor.getName();
FileDescriptor fileDescriptor = ((ProtoFileDescriptorSupplier) serviceDescriptor.getSchemaDescriptor()).getFileDescriptor();
serverFileDescriptors.add(fileDescriptor);
serverServiceNames.add(serviceName);
}
}
// Replace the index if the underlying mutable services have changed. Check both the file
// descriptors and the service names, because one file descriptor can define multiple
// services.
FileDescriptorIndex mutableServicesIndex = index.getMutableServicesIndex();
if (!mutableServicesIndex.getServiceFileDescriptors().equals(serverFileDescriptors) || !mutableServicesIndex.getServiceNames().equals(serverServiceNames)) {
index = new ServerReflectionIndex(server.getImmutableServices(), serverMutableServices);
serverReflectionIndexes.put(server, index);
}
return index;
}
}
Aggregations