Why do protobuf message fields start at 1 but enum fields start at 0?
- User
Why do protobuf message fields start at 1 but enum fields start at 0?
Assistant
This difference in numbering conventions exists for historical and practical reasons:
For Message Fields (starting at 1):
- The value 0 is used as an optimization for default/unset fields
- This allows Protocol Buffers to distinguish between an unset field (0) and an explicitly set field with value 1
- Saves space in the wire format when fields are unset
For Enums (starting at 0):
- Follows common programming language conventions where enums typically start at 0
- The first enum value must be 0 in proto3 as it's the default value
- Matches array/index behavior in most programming languages
Example:
message Person { string name = 1; // Field numbers start at 1 int32 age = 2; } enum Status { UNKNOWN = 0; // Enum values start at 0 ACTIVE = 1; INACTIVE = 2; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.