Class Descriptors.FileDescriptor

public static final class Descriptors.FileDescriptor extends Descriptors.GenericDescriptor

Describes a .proto file, including everything defined within. That includes, in particular, descriptors for all the messages and file descriptors for all other imported .proto files (dependencies).

Inheritance

java.lang.Object > Descriptors.GenericDescriptor > Descriptors.FileDescriptor

Static Methods

buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies)

public static Descriptors.FileDescriptor buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies)

Construct a FileDescriptor.

Parameters
NameDescription
protoDescriptorProtos.FileDescriptorProto

The protocol message form of the FileDescriptor.

dependenciesFileDescriptor[]

FileDescriptors corresponding to all of the file's dependencies.

Returns
TypeDescription
Descriptors.FileDescriptor
Exceptions
TypeDescription
Descriptors.DescriptorValidationException

proto is not a valid descriptor. This can occur for a number of reasons, e.g. because a field has an undefined type or because two messages were defined with the same name.

buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, boolean allowUnknownDependencies)

public static Descriptors.FileDescriptor buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, boolean allowUnknownDependencies)

Construct a FileDescriptor.

Parameters
NameDescription
protoDescriptorProtos.FileDescriptorProto

The protocol message form of the FileDescriptor.

dependenciesFileDescriptor[]

FileDescriptors corresponding to all of the file's dependencies.

allowUnknownDependenciesboolean

If true, non-exist dependenncies will be ignored and undefined message types will be replaced with a placeholder type.

Returns
TypeDescription
Descriptors.FileDescriptor
Exceptions
TypeDescription
Descriptors.DescriptorValidationException

proto is not a valid descriptor. This can occur for a number of reasons, e.g. because a field has an undefined type or because two messages were defined with the same name.

internalBuildGeneratedFileFrom(String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies)

public static Descriptors.FileDescriptor internalBuildGeneratedFileFrom(String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies)

This method is to be called by generated code only. It is equivalent to buildFrom except that the FileDescriptorProto is encoded in protocol buffer wire format.

Parameters
NameDescription
descriptorDataPartsString[]
dependenciesFileDescriptor[]
Returns
TypeDescription
Descriptors.FileDescriptor

internalBuildGeneratedFileFrom(String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner)

public static void internalBuildGeneratedFileFrom(String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner)

This method is for backward compatibility with generated code which passed an InternalDescriptorAssigner.

Parameters
NameDescription
descriptorDataPartsString[]
dependenciesFileDescriptor[]
descriptorAssignerDescriptors.FileDescriptor.InternalDescriptorAssigner

internalBuildGeneratedFileFrom(String[] descriptorDataParts, Class<?> descriptorOuterClass, String[] dependencyClassNames, String[] dependencyFileNames)

public static Descriptors.FileDescriptor internalBuildGeneratedFileFrom(String[] descriptorDataParts, Class<?> descriptorOuterClass, String[] dependencyClassNames, String[] dependencyFileNames)

This method is to be called by generated code only. It uses Java reflection to load the dependencies' descriptors.

Parameters
NameDescription
descriptorDataPartsString[]
descriptorOuterClassClass<?>
dependencyClassNamesString[]
dependencyFileNamesString[]
Returns
TypeDescription
Descriptors.FileDescriptor

internalBuildGeneratedFileFrom(String[] descriptorDataParts, Class<?> descriptorOuterClass, String[] dependencyClassNames, String[] dependencyFileNames, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner)

public static void internalBuildGeneratedFileFrom(String[] descriptorDataParts, Class<?> descriptorOuterClass, String[] dependencyClassNames, String[] dependencyFileNames, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner)

This method is for backward compatibility with generated code which passed an InternalDescriptorAssigner.

Parameters
NameDescription
descriptorDataPartsString[]
descriptorOuterClassClass<?>
dependencyClassNamesString[]
dependencyFileNamesString[]
descriptorAssignerDescriptors.FileDescriptor.InternalDescriptorAssigner

internalUpdateFileDescriptor(Descriptors.FileDescriptor descriptor, ExtensionRegistry registry)

public static void internalUpdateFileDescriptor(Descriptors.FileDescriptor descriptor, ExtensionRegistry registry)

This method is to be called by generated code only. It is used to update the FileDescriptorProto associated with the descriptor by parsing it again with the given ExtensionRegistry. This is needed to recognize custom options.

Parameters
NameDescription
descriptorDescriptors.FileDescriptor
registryExtensionRegistry

Methods

findEnumTypeByName(String name)

public Descriptors.EnumDescriptor findEnumTypeByName(String name)

Find an enum type in the file by name. Does not find nested types.

Parameter
NameDescription
nameString

The unqualified type name to look for.

Returns
TypeDescription
Descriptors.EnumDescriptor

The enum type's descriptor, or null if not found.

findExtensionByName(String name)

public Descriptors.FieldDescriptor findExtensionByName(String name)

Find an extension in the file by name. Does not find extensions nested inside message types.

Parameter
NameDescription
nameString

The unqualified extension name to look for.

Returns
TypeDescription
Descriptors.FieldDescriptor

The extension's descriptor, or null if not found.

findMessageTypeByName(String name)

public Descriptors.Descriptor findMessageTypeByName(String name)

Find a message type in the file by name. Does not find nested types.

Parameter
NameDescription
nameString

The unqualified type name to look for.

Returns
TypeDescription
Descriptors.Descriptor

The message type's descriptor, or null if not found.

findServiceByName(String name)

public Descriptors.ServiceDescriptor findServiceByName(String name)

Find a service type in the file by name.

Parameter
NameDescription
nameString

The unqualified type name to look for.

Returns
TypeDescription
Descriptors.ServiceDescriptor

The service type's descriptor, or null if not found.

getDependencies()

public List<Descriptors.FileDescriptor> getDependencies()

Get a list of this file's dependencies (imports).

Returns
TypeDescription
List<FileDescriptor>

getEnumTypes()

public List<Descriptors.EnumDescriptor> getEnumTypes()

Get a list of top-level enum types declared in this file.

Returns
TypeDescription
List<EnumDescriptor>

getExtensions()

public List<Descriptors.FieldDescriptor> getExtensions()

Get a list of top-level extensions declared in this file.

Returns
TypeDescription
List<FieldDescriptor>

getFile()

public Descriptors.FileDescriptor getFile()

Returns this object.

Returns
TypeDescription
Descriptors.FileDescriptor
Overrides

getFullName()

public String getFullName()

Returns the same as getName().

Returns
TypeDescription
String
Overrides

getMessageTypes()

public List<Descriptors.Descriptor> getMessageTypes()

Get a list of top-level message types declared in this file.

Returns
TypeDescription
List<Descriptor>

getName()

public String getName()

Get the file name.

Returns
TypeDescription
String
Overrides

getOptions()

public DescriptorProtos.FileOptions getOptions()

Get the FileOptions, defined in descriptor.proto.

Returns
TypeDescription
DescriptorProtos.FileOptions

getPackage()

public String getPackage()

Get the proto package name. This is the package name given by the package statement in the .proto file, which differs from the Java package.

Returns
TypeDescription
String

getPublicDependencies()

public List<Descriptors.FileDescriptor> getPublicDependencies()

Get a list of this file's public dependencies (public imports).

Returns
TypeDescription
List<FileDescriptor>

getServices()

public List<Descriptors.ServiceDescriptor> getServices()

Get a list of top-level services declared in this file.

Returns
TypeDescription
List<ServiceDescriptor>

getSyntax()

public Descriptors.FileDescriptor.Syntax getSyntax()

Get the syntax of the .proto file.

Returns
TypeDescription
Descriptors.FileDescriptor.Syntax

toProto()

public DescriptorProtos.FileDescriptorProto toProto()

Convert the descriptor to its protocol message representation.

Returns
TypeDescription
DescriptorProtos.FileDescriptorProto
Overrides