Create a CopyHeadingTo method for message descriptors.

This will allow users to export any metadata attached to this descriptor without also constructing every nested descriptor.  This is consistent with FileDescriptor::CopyHeadingTo, which serves a similar purpose at a different scope.

PiperOrigin-RevId: 621995153
pull/16416/head
Mike Kruskal 11 months ago committed by Copybara-Service
parent 6580c9e685
commit d74bf60768
  1. 7
      src/google/protobuf/descriptor.cc
  2. 6
      src/google/protobuf/descriptor.h

@ -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);

@ -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;

Loading…
Cancel
Save