Class Descriptors.FileDescriptor
java.lang.Object
com.google.protobuf.Descriptors.GenericDescriptor
com.google.protobuf.Descriptors.FileDescriptor
- Enclosing class:
Descriptors
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).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Descriptors.FileDescriptor[]private final Descriptors.EnumDescriptor[]private final Descriptors.FieldDescriptor[]private booleanprivate final Descriptors.Descriptor[]private DescriptorProtos.FileOptionsprivate final booleanprivate final Descriptors.FileDescriptor[]private final Descriptors.ServiceDescriptor[]private final Descriptors.FileDescriptorTablesFields inherited from class Descriptors.GenericDescriptor
features -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateFileDescriptor(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, Descriptors.FileDescriptorTables tables, boolean allowUnknownDependencies) (package private)FileDescriptor(String packageName, Descriptors.Descriptor message) Create a placeholder FileDescriptor for a message Descriptor.privateFileDescriptor(String packageName, Descriptors.Descriptor[] messages, Descriptors.EnumDescriptor[] enums, DescriptorProtos.FileDescriptorProto proto) Create a placeholder FileDescriptorprivateFileDescriptor(String packageName, Descriptors.EnumDescriptor enm) Create a placeholder FileDescriptor for an EnumDescriptor. -
Method Summary
Modifier and TypeMethodDescriptionstatic Descriptors.FileDescriptorbuildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies) Construct aFileDescriptor.static Descriptors.FileDescriptorbuildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, boolean allowUnknownDependencies) Construct aFileDescriptor.private static Descriptors.FileDescriptorbuildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, boolean allowUnknownDependencies, boolean allowUnresolvedFeatures) voidcopyHeadingTo(DescriptorProtos.FileDescriptorProto.Builder protoBuilder) private voidLook up and cross-link all field types, etc.private static Descriptors.FileDescriptor[]findDescriptors(Class<?> descriptorOuterClass, String[] dependencyClassNames, String[] dependencyFileNames) findEnumTypeByName(String name) Find an enum type in the file by name.findExtensionByName(String name) Find an extension in the file by name.findMessageTypeByName(String name) Find a message type in the file by name.findServiceByName(String name) Find a service type in the file by name.Get a list of this file's dependencies (imports).(package private) DescriptorProtos.EditionGet the edition of the .proto file.getEnumType(int index) intGet a list of top-level enum types declared in this file.getExtension(int index) intGet a list of top-level extensions declared in this file.getFile()Returns this object.Returns the same as getName().getMessageType(int index) intGet a list of top-level message types declared in this file.getName()Get the file name.Get theFileOptions, defined indescriptor.proto.Get the proto package name.(package private) Descriptors.GenericDescriptorGet a list of this file's public dependencies (public imports).getService(int index) intGet a list of top-level services declared in this file.(package private) DescriptorProtos.FeatureSetstatic Descriptors.FileDescriptorinternalBuildGeneratedFileFrom(String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies) This method is to be called by generated code only.static voidinternalBuildGeneratedFileFrom(String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner) Deprecated.Any gencode which is using this method is far out of support and should be regenerated with a newer version of the protobuf compiler.static Descriptors.FileDescriptorinternalBuildGeneratedFileFrom(String[] descriptorDataParts, Class<?> descriptorOuterClass, String[] dependencyClassNames, String[] dependencyFileNames) This method is to be called by generated code only.static voidinternalUpdateFileDescriptor(Descriptors.FileDescriptor descriptor, ExtensionRegistry registry) This method is to be called by generated code only.booleanprivate static byte[]voidprivate voidThis method is to be called by generated code only.private voidReplace ourDescriptorProtos.FileDescriptorProtowith the given one, which is identical except that it might contain extensions that weren't present in the original.toProto()Convert the descriptor to its protocol message representation.Methods inherited from class Descriptors.GenericDescriptor
getFeatures, resolveFeatures, validateFeatures
-
Field Details
-
proto
-
options
-
messageTypes
-
enumTypes
-
services
-
extensions
-
dependencies
-
publicDependencies
-
tables
-
placeholder
private final boolean placeholder -
featuresResolved
private volatile boolean featuresResolved
-
-
Constructor Details
-
FileDescriptor
private FileDescriptor(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, Descriptors.FileDescriptorTables tables, boolean allowUnknownDependencies) throws Descriptors.DescriptorValidationException -
FileDescriptor
private FileDescriptor(String packageName, Descriptors.Descriptor[] messages, Descriptors.EnumDescriptor[] enums, DescriptorProtos.FileDescriptorProto proto) throws Descriptors.DescriptorValidationException Create a placeholder FileDescriptor -
FileDescriptor
FileDescriptor(String packageName, Descriptors.Descriptor message) throws Descriptors.DescriptorValidationException Create a placeholder FileDescriptor for a message Descriptor. -
FileDescriptor
private FileDescriptor(String packageName, Descriptors.EnumDescriptor enm) throws Descriptors.DescriptorValidationException Create a placeholder FileDescriptor for an EnumDescriptor.
-
-
Method Details
-
toProto
Convert the descriptor to its protocol message representation.- Specified by:
toProtoin classDescriptors.GenericDescriptor
-
getName
Get the file name.- Specified by:
getNamein classDescriptors.GenericDescriptor
-
getFile
Returns this object.- Specified by:
getFilein classDescriptors.GenericDescriptor
-
getParent
Descriptors.GenericDescriptor getParent()- Specified by:
getParentin classDescriptors.GenericDescriptor
-
isPlaceholder
public boolean isPlaceholder() -
getFullName
Returns the same as getName().- Specified by:
getFullNamein classDescriptors.GenericDescriptor
-
getPackage
Get the proto package name. This is the package name given by thepackagestatement in the.protofile, which differs from the Java package. -
getOptions
Get theFileOptions, defined indescriptor.proto. -
getMessageTypes
Get a list of top-level message types declared in this file. -
getMessageTypeCount
public int getMessageTypeCount() -
getMessageType
-
getEnumTypes
Get a list of top-level enum types declared in this file. -
getEnumTypeCount
public int getEnumTypeCount() -
getEnumType
-
getServices
Get a list of top-level services declared in this file. -
getServiceCount
public int getServiceCount() -
getService
-
getExtensions
Get a list of top-level extensions declared in this file. -
getExtensionCount
public int getExtensionCount() -
getExtension
-
getDependencies
Get a list of this file's dependencies (imports). -
getPublicDependencies
Get a list of this file's public dependencies (public imports). -
getEdition
DescriptorProtos.Edition getEdition()Get the edition of the .proto file. -
copyHeadingTo
-
findMessageTypeByName
Find a message type in the file by name. Does not find nested types.- Parameters:
name- The unqualified type name to look for.- Returns:
- The message type's descriptor, or
nullif not found.
-
findEnumTypeByName
Find an enum type in the file by name. Does not find nested types.- Parameters:
name- The unqualified type name to look for.- Returns:
- The enum type's descriptor, or
nullif not found.
-
findServiceByName
Find a service type in the file by name.- Parameters:
name- The unqualified type name to look for.- Returns:
- The service type's descriptor, or
nullif not found.
-
findExtensionByName
Find an extension in the file by name. Does not find extensions nested inside message types.- Parameters:
name- The unqualified extension name to look for.- Returns:
- The extension's descriptor, or
nullif not found.
-
buildFrom
public static Descriptors.FileDescriptor buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies) throws Descriptors.DescriptorValidationException Construct aFileDescriptor.- Parameters:
proto- the protocol message form of the FileDescriptortdependencies-FileDescriptors corresponding to all of the file's dependencies.- Throws:
Descriptors.DescriptorValidationException-protois not a valid descriptor. This can occur for a number of reasons; for instance, because a field has an undefined type or because two messages were defined with the same name.
-
buildFrom
public static Descriptors.FileDescriptor buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, boolean allowUnknownDependencies) throws Descriptors.DescriptorValidationException Construct aFileDescriptor.- Parameters:
proto- the protocol message form of the FileDescriptordependencies-FileDescriptors corresponding to all of the file's dependenciesallowUnknownDependencies- if true, non-existing dependencies will be ignored and undefined message types will be replaced with a placeholder type. Undefined enum types still cause a DescriptorValidationException.- Throws:
Descriptors.DescriptorValidationException-protois not a valid descriptor. This can occur for a number of reasons; for instance, because a field has an undefined type or because two messages were defined with the same name.
-
buildFrom
private static Descriptors.FileDescriptor buildFrom(DescriptorProtos.FileDescriptorProto proto, Descriptors.FileDescriptor[] dependencies, boolean allowUnknownDependencies, boolean allowUnresolvedFeatures) throws Descriptors.DescriptorValidationException -
latin1Cat
-
findDescriptors
private static Descriptors.FileDescriptor[] findDescriptors(Class<?> descriptorOuterClass, String[] dependencyClassNames, String[] dependencyFileNames) -
internalBuildGeneratedFileFrom
@Deprecated public static void internalBuildGeneratedFileFrom(String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies, Descriptors.FileDescriptor.InternalDescriptorAssigner descriptorAssigner) Deprecated.Any gencode which is using this method is far out of support and should be regenerated with a newer version of the protobuf compiler.This method is for backward compatibility with generated code which passed an InternalDescriptorAssigner. -
internalBuildGeneratedFileFrom
public static Descriptors.FileDescriptor internalBuildGeneratedFileFrom(String[] descriptorDataParts, Descriptors.FileDescriptor[] dependencies) This method is to be called by generated code only. It is equivalent tobuildFromexcept that theFileDescriptorProtois encoded in protocol buffer wire format. -
internalBuildGeneratedFileFrom
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. -
internalUpdateFileDescriptor
public static void internalUpdateFileDescriptor(Descriptors.FileDescriptor descriptor, ExtensionRegistry registry) This method is to be called by generated code only. It updates the FileDescriptorProto associated with the descriptor by parsing it again with the given ExtensionRegistry. This is needed to recognize custom options. -
resolveAllFeaturesImmutable
public void resolveAllFeaturesImmutable() -
resolveAllFeaturesInternal
This method is to be called by generated code only. It resolves features for the descriptor and all of its children. -
inferLegacyProtoFeatures
DescriptorProtos.FeatureSet inferLegacyProtoFeatures()- Overrides:
inferLegacyProtoFeaturesin classDescriptors.GenericDescriptor
-
crossLink
Look up and cross-link all field types, etc. -
setProto
Replace ourDescriptorProtos.FileDescriptorProtowith the given one, which is identical except that it might contain extensions that weren't present in the original. This method is needed for bootstrapping when a file defines custom options. The options may be defined in the file itself, so we can't actually parse them until we've constructed the descriptors, but to construct the descriptors we have to have parsed the descriptor protos. So, we have to parse the descriptor protos a second time after constructing the descriptors.
-