Skip to content

Commit f92335b

Browse files
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
1 parent 84a4472 commit f92335b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/google/protobuf/descriptor.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase {
409409
// The number of fields in this message type.
410410
int field_count() const;
411411
// Gets a field by index, where 0 <= index < field_count().
412-
// These are returned in the order they were defined in the .proto file.
412+
// These are returned in the order they were defined in the .proto file, not
413+
// the field number order. (Use `FindFieldByNumber()` for
414+
// tag number -> value lookup).
413415
const FieldDescriptor* field(int index) const;
414416

415417
// 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 {
13211323
// than zero.
13221324
int value_count() const;
13231325
// Gets a value by index, where 0 <= index < value_count().
1324-
// These are returned in the order they were defined in the .proto file.
1326+
// These are returned in the order they were defined in the .proto file, not
1327+
// the enum value order. (Use `FindValueByNumber()` for enum -> value lookup).
13251328
const EnumValueDescriptor* value(int index) const;
13261329

13271330
// Looks up a value by name. Returns nullptr if no such value exists.

0 commit comments

Comments
 (0)