Skip to content

Commit

Permalink
Comment change: clarifies that the field/value order is based on text…
Browse files Browse the repository at this point in the history
…ual 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
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Oct 21, 2024
1 parent 84a4472 commit f92335b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/google/protobuf/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f92335b

Please sign in to comment.