From f92335b36db1bad089c3bccddc90bded98cb6a16 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 21 Oct 2024 15:39:56 -0700 Subject: [PATCH] Comment change: clarifies that the field/value order is based on textual order in the file, not the order of the enums. Clarifies that reordering `enum` fields (even without changing their IDs) will change the order of the `value` indices. (This means that a seemingly "no-op" change to reorganize enums may affect code that (incorrectly) relied on the order of `value()`. PiperOrigin-RevId: 688297400 --- src/google/protobuf/descriptor.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 206ea1f95c..9ac7462403 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -409,7 +409,9 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { // The number of fields in this message type. int field_count() const; // Gets a field by index, where 0 <= index < field_count(). - // These are returned in the order they were defined in the .proto file. + // These are returned in the order they were defined in the .proto file, not + // the field number order. (Use `FindFieldByNumber()` for + // tag number -> value lookup). const FieldDescriptor* field(int index) const; // Looks up a field by declared tag number. Returns nullptr if no such field @@ -1321,7 +1323,8 @@ class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase { // than zero. int value_count() const; // Gets a value by index, where 0 <= index < value_count(). - // These are returned in the order they were defined in the .proto file. + // These are returned in the order they were defined in the .proto file, not + // the enum value order. (Use `FindValueByNumber()` for enum -> value lookup). const EnumValueDescriptor* value(int index) const; // Looks up a value by name. Returns nullptr if no such value exists.