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.h117
1 files changed, 100 insertions, 17 deletions
diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h
index 68013f8e..b7ea756c 100644
--- a/src/google/protobuf/descriptor.h
+++ b/src/google/protobuf/descriptor.h
@@ -104,6 +104,11 @@ class FileDescriptorTables;
// Defined in unknown_field_set.h.
class UnknownField;
+// Defined in generated_message_reflection.h.
+namespace internal {
+ class GeneratedMessageReflection;
+}
+
// NB, all indices are zero-based.
struct SourceLocation {
int start_line;
@@ -118,6 +123,20 @@ struct SourceLocation {
string trailing_comments;
};
+// Options when generating machine-parsable output from a descriptor with
+// DebugString().
+struct DebugStringOptions {
+ // include original user comments as recorded in SourceLocation entries. N.B.
+ // that this must be |false| by default: several other pieces of code (for
+ // example, the C++ code generation for fields in the proto compiler) rely on
+ // DebugString() output being unobstructed by user comments.
+ bool include_comments;
+
+ DebugStringOptions()
+ : include_comments(false)
+ {}
+};
+
// Describes a type of protocol message, or a particular group within a
// message. To obtain the Descriptor for a given message object, call
// Message::GetDescriptor(). Generated message classes also have a
@@ -162,6 +181,10 @@ class LIBPROTOBUF_EXPORT Descriptor {
// will be suitable for re-parsing.
string DebugString() const;
+ // Similar to DebugString(), but additionally takes options (e.g.,
+ // include original user comments in output).
+ string DebugStringWithOptions(const DebugStringOptions& options) const;
+
// Returns true if this is a placeholder for an unknown type. This will
// only be the case if this descriptor comes from a DescriptorPool
// with AllowUnknownDependencies() set.
@@ -282,8 +305,12 @@ class LIBPROTOBUF_EXPORT Descriptor {
typedef MessageOptions OptionsType;
// Internal version of DebugString; controls the level of indenting for
- // correct depth
- void DebugString(int depth, string *contents) const;
+ // correct depth. Takes |options| to control debug-string options, and
+ // |include_opening_clause| to indicate whether the "message ... " part of the
+ // clause has already been generated (this varies depending on context).
+ void DebugString(int depth, string *contents,
+ const DebugStringOptions& options,
+ bool include_opening_clause) const;
// Walks up the descriptor tree to generate the source location path
// to this descriptor from the file root.
@@ -513,12 +540,6 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
// returns null.
const EnumDescriptor* enum_type() const;
- // EXPERIMENTAL; DO NOT USE.
- // If this field is a map field, experimental_map_key() is the field
- // that is the key for this map.
- // experimental_map_key()->containing_type() is the same as message_type().
- const FieldDescriptor* experimental_map_key() const;
-
// Get the FieldOptions for this field. This includes things listed in
// square brackets after the field definition. E.g., the field:
// optional string text = 1 [ctype=CORD];
@@ -533,6 +554,9 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
// See Descriptor::DebugString().
string DebugString() const;
+ // See Descriptor::DebugStringWithOptions().
+ string DebugStringWithOptions(const DebugStringOptions& options) const;
+
// Helper method to get the CppType for a particular Type.
static CppType TypeToCppType(Type type);
@@ -558,13 +582,16 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
// See Descriptor::DebugString().
enum PrintLabelFlag { PRINT_LABEL, OMIT_LABEL };
void DebugString(int depth, PrintLabelFlag print_label_flag,
- string* contents) const;
+ string* contents, const DebugStringOptions& options) const;
// formats the default value appropriately and returns it as a string.
// Must have a default value to call this. If quote_string_type is true, then
// types of CPPTYPE_STRING whill be surrounded by quotes and CEscaped.
string DefaultValueAsString(bool quote_string_type) const;
+ // Helper function that returns the field type name for DebugString.
+ string FieldTypeNameDebugString() const;
+
// Walks up the descriptor tree to generate the source location path
// to this descriptor from the file root.
void GetLocationPath(vector<int>* output) const;
@@ -584,7 +611,6 @@ class LIBPROTOBUF_EXPORT FieldDescriptor {
const Descriptor* extension_scope_;
const Descriptor* message_type_;
const EnumDescriptor* enum_type_;
- const FieldDescriptor* experimental_map_key_;
const FieldOptions* options_;
// IMPORTANT: If you add a new field, make sure to search for all instances
// of Allocate<FieldDescriptor>() and AllocateArray<FieldDescriptor>() in
@@ -645,6 +671,9 @@ class LIBPROTOBUF_EXPORT OneofDescriptor {
// See Descriptor::DebugString().
string DebugString() const;
+ // See Descriptor::DebugStringWithOptions().
+ string DebugStringWithOptions(const DebugStringOptions& options) const;
+
// Source Location ---------------------------------------------------
// Updates |*out_location| to the source location of the complete
@@ -654,7 +683,8 @@ class LIBPROTOBUF_EXPORT OneofDescriptor {
private:
// See Descriptor::DebugString().
- void DebugString(int depth, string* contents) const;
+ void DebugString(int depth, string* contents,
+ const DebugStringOptions& options) const;
// Walks up the descriptor tree to generate the source location path
// to this descriptor from the file root.
@@ -723,6 +753,10 @@ class LIBPROTOBUF_EXPORT EnumDescriptor {
// See Descriptor::DebugString().
string DebugString() const;
+ // See Descriptor::DebugStringWithOptions().
+ string DebugStringWithOptions(const DebugStringOptions& options) const;
+
+
// Returns true if this is a placeholder for an unknown enum. This will
// only be the case if this descriptor comes from a DescriptorPool
// with AllowUnknownDependencies() set.
@@ -738,8 +772,21 @@ class LIBPROTOBUF_EXPORT EnumDescriptor {
private:
typedef EnumOptions OptionsType;
+ // Looks up a value by number. If the value does not exist, dynamically
+ // creates a new EnumValueDescriptor for that value, assuming that it was
+ // unknown. If a new descriptor is created, this is done in a thread-safe way,
+ // and future calls will return the same value descriptor pointer.
+ //
+ // This is private but is used by GeneratedMessageReflection (which is
+ // friended below) to return a valid EnumValueDescriptor from GetEnum() when
+ // this feature is enabled.
+ const EnumValueDescriptor*
+ FindValueByNumberCreatingIfUnknown(int number) const;
+
+
// See Descriptor::DebugString().
- void DebugString(int depth, string *contents) const;
+ void DebugString(int depth, string *contents,
+ const DebugStringOptions& options) const;
// Walks up the descriptor tree to generate the source location path
// to this descriptor from the file root.
@@ -769,6 +816,7 @@ class LIBPROTOBUF_EXPORT EnumDescriptor {
friend class FieldDescriptor;
friend class EnumValueDescriptor;
friend class FileDescriptor;
+ friend class LIBPROTOBUF_EXPORT internal::GeneratedMessageReflection;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor);
};
@@ -806,6 +854,10 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptor {
// See Descriptor::DebugString().
string DebugString() const;
+ // See Descriptor::DebugStringWithOptions().
+ string DebugStringWithOptions(const DebugStringOptions& options) const;
+
+
// Source Location ---------------------------------------------------
// Updates |*out_location| to the source location of the complete
@@ -817,7 +869,8 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptor {
typedef EnumValueOptions OptionsType;
// See Descriptor::DebugString().
- void DebugString(int depth, string *contents) const;
+ void DebugString(int depth, string *contents,
+ const DebugStringOptions& options) const;
// Walks up the descriptor tree to generate the source location path
// to this descriptor from the file root.
@@ -836,6 +889,7 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptor {
EnumValueDescriptor() {}
friend class DescriptorBuilder;
friend class EnumDescriptor;
+ friend class FileDescriptorTables;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor);
};
@@ -876,6 +930,10 @@ class LIBPROTOBUF_EXPORT ServiceDescriptor {
// See Descriptor::DebugString().
string DebugString() const;
+ // See Descriptor::DebugStringWithOptions().
+ string DebugStringWithOptions(const DebugStringOptions& options) const;
+
+
// Source Location ---------------------------------------------------
// Updates |*out_location| to the source location of the complete
@@ -887,7 +945,7 @@ class LIBPROTOBUF_EXPORT ServiceDescriptor {
typedef ServiceOptions OptionsType;
// See Descriptor::DebugString().
- void DebugString(string *contents) const;
+ void DebugString(string *contents, const DebugStringOptions& options) const;
// Walks up the descriptor tree to generate the source location path
// to this descriptor from the file root.
@@ -945,6 +1003,10 @@ class LIBPROTOBUF_EXPORT MethodDescriptor {
// See Descriptor::DebugString().
string DebugString() const;
+ // See Descriptor::DebugStringWithOptions().
+ string DebugStringWithOptions(const DebugStringOptions& options) const;
+
+
// Source Location ---------------------------------------------------
// Updates |*out_location| to the source location of the complete
@@ -956,7 +1018,8 @@ class LIBPROTOBUF_EXPORT MethodDescriptor {
typedef MethodOptions OptionsType;
// See Descriptor::DebugString().
- void DebugString(int depth, string *contents) const;
+ void DebugString(int depth, string *contents,
+ const DebugStringOptions& options) const;
// Walks up the descriptor tree to generate the source location path
// to this descriptor from the file root.
@@ -1052,6 +1115,15 @@ class LIBPROTOBUF_EXPORT FileDescriptor {
// message.
const FileOptions& options() const;
+ // Syntax of this file.
+ enum Syntax {
+ SYNTAX_UNKNOWN = 0,
+ SYNTAX_PROTO2 = 2,
+ SYNTAX_PROTO3 = 3,
+ };
+ Syntax syntax() const;
+ static const char* SyntaxName(Syntax syntax);
+
// Find a top-level message type by name. Returns NULL if not found.
const Descriptor* FindMessageTypeByName(const string& name) const;
// Find a top-level enum type by name. Returns NULL if not found.
@@ -1082,11 +1154,18 @@ class LIBPROTOBUF_EXPORT FileDescriptor {
// See Descriptor::DebugString().
string DebugString() const;
+ // See Descriptor::DebugStringWithOptions().
+ string DebugStringWithOptions(const DebugStringOptions& options) const;
+
// Returns true if this is a placeholder for an unknown file. This will
// only be the case if this descriptor comes from a DescriptorPool
// with AllowUnknownDependencies() set.
bool is_placeholder() const;
+ // Updates |*out_location| to the source location of the complete extent of
+ // this file declaration (namely, the empty path).
+ bool GetSourceLocation(SourceLocation* out_location) const;
+
private:
// Source Location ---------------------------------------------------
@@ -1116,6 +1195,7 @@ class LIBPROTOBUF_EXPORT FileDescriptor {
int service_count_;
ServiceDescriptor* services_;
int extension_count_;
+ Syntax syntax_;
bool is_placeholder_;
FieldDescriptor* extensions_;
const FileOptions* options_;
@@ -1394,6 +1474,7 @@ class LIBPROTOBUF_EXPORT DescriptorPool {
friend class ServiceDescriptor;
friend class FileDescriptor;
friend class DescriptorBuilder;
+ friend class FileDescriptorTables;
// Return true if the given name is a sub-symbol of any non-package
// descriptor that already exists in the descriptor pool. (The full
@@ -1494,8 +1575,6 @@ PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, index_in_oneof, int)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, extension_scope, const Descriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*)
-PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, experimental_map_key,
- const FieldDescriptor*)
PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool)
PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32 , int32 )
@@ -1679,6 +1758,10 @@ inline const FileDescriptor* FileDescriptor::weak_dependency(
return dependencies_[weak_dependencies_[index]];
}
+inline FileDescriptor::Syntax FileDescriptor::syntax() const {
+ return syntax_;
+}
+
// Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because fields_ is actually an array
// of pointers rather than the usual array of objects.
inline const FieldDescriptor* OneofDescriptor::field(int index) const {