diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 8d8cff8393..a63a1d46b9 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -2791,7 +2791,7 @@ void FileDescriptor::CopySourceCodeInfoTo(FileDescriptorProto* proto) const { } void Descriptor::CopyTo(DescriptorProto* proto) const { - proto->set_name(name()); + CopyHeadingTo(proto); for (int i = 0; i < field_count(); i++) { field(i)->CopyTo(proto->add_field()); @@ -2811,6 +2811,11 @@ void Descriptor::CopyTo(DescriptorProto* proto) const { for (int i = 0; i < extension_count(); i++) { extension(i)->CopyTo(proto->add_extension()); } +} + +void Descriptor::CopyHeadingTo(DescriptorProto* proto) const { + proto->set_name(name()); + for (int i = 0; i < reserved_range_count(); i++) { DescriptorProto::ReservedRange* range = proto->add_reserved_range(); range->set_start(reserved_range(i)->start); diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 13446c7d91..2cd35c2331 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -339,6 +339,12 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { // isn't, the result may be garbage. void CopyTo(DescriptorProto* proto) const; + // Fills in the message-level settings of this message (e.g. name, reserved + // fields, message options) to `proto`. This is essentially all of the + // metadata owned exclusively by this descriptor, and not any nested + // descriptors. + void CopyHeadingTo(DescriptorProto* proto) const; + // Write the contents of this descriptor in a human-readable form. Output // will be suitable for re-parsing. std::string DebugString() const;