Enums & Flags
IonPath supports both single-value enumerations (enum) and bitfield enumerations (flags).
Enums
Enums define a set of named constants with auto-incrementing values:
enum Status: u1 { Pending, // = 0 Active, // = 1 Inactive = 5, // = 5 (explicit) Archived // = 6 (auto-increment from 5) }
The base type (after the colon) determines the wire encoding size. Can be any unsigned integer: u1, u2, u4, u8.
Flags
Flags are bitfield enums — their values can be combined with bitwise OR. Use the bit-shift syntax for clarity:
flags Permissions: u4 { None = 0, Read = 1 << 0, // = 1 Write = 1 << 1, // = 2 Execute = 1 << 2, // = 4 Admin = 1 << 3, // = 8 All = 15 // = 0b1111 }
Enum vs Flags
Feature enum / flags
Value semantics enum: exactly one value. flags: combinable via bitwise OR.
Auto-increment enum: sequential (+1). flags: no auto-increment — all values must be explicit.
Bit overlap check flags only: compiler detects overlapping bits (ION0011).
C# attribute flags: generates
[Flags] attribute. Validation Rules
- ION0006 — Duplicate member names within the same enum/flags
- ION0007 — Non-constant values (only integer literals and bit-shift expressions allowed)
- ION0008 — Duplicate values (two members with the same numeric value in an enum)
- ION0011 — Overlapping bits in flags (e.g.,
3overlaps with1and2)
Using Enums and Flags
enum UserRole: u1 { Guest, Member, Moderator, Admin } flags UserFlags: u4 { None = 0, Verified = 1 << 0, Premium = 1 << 1, Bot = 1 << 2 } msg User { id: u4; role: UserRole; flags: UserFlags; }