A field identifier is the unique numeric tag assigned to a field in a Protobuf message. Consumers use it to recognize serialized fields across API versions. section 10.1.1
When defining Protobuf fields:
- Assign every field a unique numeric identifier. section 10.1.1
- Keep an identifier permanently associated with its field; renumbering can break backward compatibility. section 10.1.1
- Use incremental numbering when practical, without leaving gaps. section 10.1.1
Listing 10.3 habit.proto: Defining the Habit message
// Habit represents an objective one wants to complete
// a given number of times per week.
message Habit { #1
// Name of the habit, cannot be empty
string name = 1; #2
// Frequency, expressed in times per week.
int32 weekly_frequency = 2;
}
A compact Habit message assigns name the identifier 1 and weekly_frequency the identifier 2. section 10.1.1
