Module 2: Enums, Repeated Fields & Lists
Defining Enums
Progress: 1 / 2 Lessons
Step 1
Defining Enums
Enums in Protobuf
Enums allow you to define a list of predefined values. **Crucial Rule:** The first element in a proto3 enum MUST map to zero (0). This zero value becomes the default value.``
protobuf
enum Status {
STATUS_UNKNOWN = 0; // Must be 0
STATUS_ACTIVE = 1;
}
`
---
Your Challenge:
1. Define an enum named Role.
2. Add ROLE_UNKNOWN = 0;, ROLE_USER = 1;, and ROLE_ADMIN = 2;.
3. Add a role field of type Role to UserProfile with tag 8`.
Criteria (0 / 2)
Action Requiredâ—‹
Defines Role enum
Enum 'Role' is missing
â—‹
UserProfile has Role role = 8
Field 'role' is missing
Type required .proto code in editor to pass.
schema.proto|proto3
UTF-8Monaco Engine
Loading Monaco Editor...
proto3package user.service
Messages1
UserProfile
optionalstringid
Tag = 1