aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/descriptor.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/descriptor.h')
-rw-r--r--src/google/protobuf/descriptor.h98
1 files changed, 66 insertions, 32 deletions
diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h
index 7aea7344..57128e6b 100644
--- a/src/google/protobuf/descriptor.h
+++ b/src/google/protobuf/descriptor.h
@@ -99,6 +99,7 @@ class FieldOptions;
class OneofOptions;
class EnumOptions;
class EnumValueOptions;
+class ExtensionRangeOptions;
class ServiceOptions;
class MethodOptions;
class FileOptions;
@@ -337,8 +338,12 @@ class LIBPROTOBUF_EXPORT Descriptor {
// A range of field numbers which are designated for third-party
// extensions.
struct ExtensionRange {
+ typedef ExtensionRangeOptions OptionsType;
+
int start; // inclusive
int end; // exclusive
+
+ const ExtensionRangeOptions* options_;
};
// The number of extension ranges in this message type.
@@ -440,27 +445,30 @@ class LIBPROTOBUF_EXPORT Descriptor {
const Descriptor* containing_type_;
const MessageOptions* options_;
- // True if this is a placeholder for an unknown type.
- bool is_placeholder_;
- // True if this is a placeholder and the type name wasn't fully-qualified.
- bool is_unqualified_placeholder_;
+ // These arrays are separated from their sizes to minimize padding on 64-bit.
+ FieldDescriptor* fields_;
+ OneofDescriptor* oneof_decls_;
+ Descriptor* nested_types_;
+ EnumDescriptor* enum_types_;
+ ExtensionRange* extension_ranges_;
+ FieldDescriptor* extensions_;
+ ReservedRange* reserved_ranges_;
+ const string** reserved_names_;
int field_count_;
- FieldDescriptor* fields_;
int oneof_decl_count_;
- OneofDescriptor* oneof_decls_;
int nested_type_count_;
- Descriptor* nested_types_;
int enum_type_count_;
- EnumDescriptor* enum_types_;
int extension_range_count_;
- ExtensionRange* extension_ranges_;
int extension_count_;
- FieldDescriptor* extensions_;
int reserved_range_count_;
- ReservedRange* reserved_ranges_;
int reserved_name_count_;
- const string** reserved_names_;
+
+ // True if this is a placeholder for an unknown type.
+ bool is_placeholder_;
+ // True if this is a placeholder and the type name wasn't fully-qualified.
+ bool is_unqualified_placeholder_;
+
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<Descriptor>() and AllocateArray<Descriptor>() in descriptor.cc
// and update them to initialize the field.
@@ -477,6 +485,7 @@ class LIBPROTOBUF_EXPORT Descriptor {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor);
};
+
// Describes a single field of a message. To get the descriptor for a given
// field, first get the Descriptor for the message in which it is defined,
// then call Descriptor::FindFieldByName(). To get a FieldDescriptor for
@@ -736,20 +745,21 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
const string* full_name_;
const string* lowercase_name_;
const string* camelcase_name_;
- // Whether the user has specified the json_name field option in the .proto
- // file.
- bool has_json_name_;
// If has_json_name_ is true, it's the value specified by the user.
// Otherwise, it has the same value as camelcase_name_.
const string* json_name_;
const FileDescriptor* file_;
- int number_;
GoogleOnceDynamic* type_once_;
static void TypeOnceInit(const FieldDescriptor* to_init);
void InternalTypeOnceInit() const;
mutable Type type_;
Label label_;
+ bool has_default_value_;
+ // Whether the user has specified the json_name field option in the .proto
+ // file.
+ bool has_json_name_;
bool is_extension_;
+ int number_;
int index_in_oneof_;
const Descriptor* containing_type_;
const OneofDescriptor* containing_oneof_;
@@ -763,7 +773,6 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
// of Allocate<FieldDescriptor>() and AllocateArray<FieldDescriptor>() in
// descriptor.cc and update them to initialize the field.
- bool has_default_value_;
union {
int32 default_value_int32_;
int64 default_value_int64_;
@@ -794,6 +803,7 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor);
};
+
// Describes a oneof defined in a message type.
class LIBPROTOBUF_EXPORT OneofDescriptor {
public:
@@ -803,6 +813,8 @@ class LIBPROTOBUF_EXPORT OneofDescriptor {
// Index of this oneof within the message's oneof array.
int index() const;
+ // The .proto file in which this oneof was defined. Never NULL.
+ const FileDescriptor* file() const;
// The Descriptor for the message containing this oneof.
const Descriptor* containing_type() const;
@@ -998,6 +1010,8 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptor {
// with C++ scoping rules for enums.
const string& full_name() const;
+ // The .proto file in which this value was defined. Never NULL.
+ const FileDescriptor* file() const;
// The type of this value. Never NULL.
const EnumDescriptor* type() const;
@@ -1122,8 +1136,8 @@ class LIBPROTOBUF_EXPORT ServiceDescriptor {
const string* full_name_;
const FileDescriptor* file_;
const ServiceOptions* options_;
- int method_count_;
MethodDescriptor* methods_;
+ int method_count_;
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<ServiceDescriptor>() and AllocateArray<ServiceDescriptor>() in
// descriptor.cc and update them to initialize the field.
@@ -1136,6 +1150,7 @@ class LIBPROTOBUF_EXPORT ServiceDescriptor {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor);
};
+
// Describes an individual service method. To obtain a MethodDescriptor given
// a service, first get its ServiceDescriptor, then call
// ServiceDescriptor::FindMethodByName(). Use DescriptorPool to construct your
@@ -1149,6 +1164,8 @@ class LIBPROTOBUF_EXPORT MethodDescriptor {
// Index within the service's Descriptor.
int index() const;
+ // The .proto file in which this method was defined. Never NULL.
+ const FileDescriptor* file() const;
// Gets the service to which this method belongs. Never NULL.
const ServiceDescriptor* service() const;
@@ -1360,36 +1377,39 @@ class LIBPROTOBUF_EXPORT FileDescriptor {
const string* name_;
const string* package_;
const DescriptorPool* pool_;
- int dependency_count_;
- mutable const FileDescriptor** dependencies_;
- const string** dependencies_names_;
GoogleOnceDynamic* dependencies_once_;
static void DependenciesOnceInit(const FileDescriptor* to_init);
void InternalDependenciesOnceInit() const;
+
+ // These are arranged to minimze padding on 64-bit.
+ int dependency_count_;
int public_dependency_count_;
- int* public_dependencies_;
int weak_dependency_count_;
- int* weak_dependencies_;
int message_type_count_;
- Descriptor* message_types_;
int enum_type_count_;
- EnumDescriptor* enum_types_;
int service_count_;
- ServiceDescriptor* services_;
int extension_count_;
Syntax syntax_;
bool is_placeholder_;
- FieldDescriptor* extensions_;
- const FileOptions* options_;
-
- const FileDescriptorTables* tables_;
- const SourceCodeInfo* source_code_info_;
// Indicates the FileDescriptor is completed building. Used to verify
// that type accessor functions that can possibly build a dependent file
// aren't called during the process of building the file.
bool finished_building_;
+ mutable const FileDescriptor** dependencies_;
+ const string** dependencies_names_;
+ int* public_dependencies_;
+ int* weak_dependencies_;
+ Descriptor* message_types_;
+ EnumDescriptor* enum_types_;
+ ServiceDescriptor* services_;
+ FieldDescriptor* extensions_;
+ const FileOptions* options_;
+
+ const FileDescriptorTables* tables_;
+ const SourceCodeInfo* source_code_info_;
+
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<FileDescriptor>() and AllocateArray<FileDescriptor>() in
// descriptor.cc and update them to initialize the field.
@@ -1408,6 +1428,7 @@ class LIBPROTOBUF_EXPORT FileDescriptor {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor);
};
+
// ===================================================================
// Used to construct descriptors.
@@ -1748,12 +1769,13 @@ class LIBPROTOBUF_EXPORT DescriptorPool {
bool lazily_build_dependencies_;
bool allow_unknown_;
bool enforce_weak_;
- std::set<string> unused_import_track_files_;
bool disallow_enforce_utf8_;
+ std::set<string> unused_import_track_files_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool);
};
+
// inline methods ====================================================
// These macros makes this repetitive code more readable.
@@ -1949,6 +1971,10 @@ inline int Descriptor::index() const {
}
}
+inline const FileDescriptor* OneofDescriptor::file() const {
+ return containing_type()->file();
+}
+
inline int OneofDescriptor::index() const {
return static_cast<int>(this - containing_type_->oneof_decls_);
}
@@ -1961,6 +1987,10 @@ inline int EnumDescriptor::index() const {
}
}
+inline const FileDescriptor* EnumValueDescriptor::file() const {
+ return type()->file();
+}
+
inline int EnumValueDescriptor::index() const {
return static_cast<int>(this - type_->values_);
}
@@ -1969,6 +1999,10 @@ inline int ServiceDescriptor::index() const {
return static_cast<int>(this - file_->services_);
}
+inline const FileDescriptor* MethodDescriptor::file() const {
+ return service()->file();
+}
+
inline int MethodDescriptor::index() const {
return static_cast<int>(this - service_->methods_);
}