Search in sources :

Example 11 with FileDescriptor

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);
}
Also used : FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto)

Example 12 with FileDescriptor

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);
        }
    }
}
Also used : FileDescriptorSet(com.google.protobuf.DescriptorProtos.FileDescriptorSet) DescriptorValidationException(com.google.protobuf.Descriptors.DescriptorValidationException) IOException(java.io.IOException) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor)

Example 13 with FileDescriptor

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;
    }
}
Also used : Server(io.grpc.Server) InternalServer(io.grpc.InternalServer) ProtoFileDescriptorSupplier(io.grpc.protobuf.ProtoFileDescriptorSupplier) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) ServerServiceDefinition(io.grpc.ServerServiceDefinition) HashSet(java.util.HashSet)

Aggregations

FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)13 FileDescriptorProto (com.google.protobuf.DescriptorProtos.FileDescriptorProto)7 DescriptorValidationException (com.google.protobuf.Descriptors.DescriptorValidationException)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 DescriptorProto (com.google.protobuf.DescriptorProtos.DescriptorProto)2 FieldDescriptorProto (com.google.protobuf.DescriptorProtos.FieldDescriptorProto)2 ServerServiceDefinition (io.grpc.ServerServiceDefinition)2 ProtoFileDescriptorSupplier (io.grpc.protobuf.ProtoFileDescriptorSupplier)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 FileDescriptorSet (com.google.protobuf.DescriptorProtos.FileDescriptorSet)1 Descriptor (com.google.protobuf.Descriptors.Descriptor)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Message (com.google.protobuf.Message)1 JsonFormat (com.googlecode.protobuf.format.JsonFormat)1 ParseException (com.googlecode.protobuf.format.JsonFormat.ParseException)1 FileDescriptorTreeProto (com.palantir.atlasdb.protos.generated.TableMetadataPersistence.FileDescriptorTreeProto)1 Person (com.twitter.elephantbird.thrift.test.Person)1 InternalServer (io.grpc.InternalServer)1