Updating Enumerations
The enumerations in src/siso/enums.rs come from SISO-REF-010 which SISO
revises regularly. The crate currently follows SISO-REF-010-2023. This page
covers the conventions for enumerations and how to move the crate to a new revision.
Enumerations explains what SISO-REF-010 is and how users see these types.
Conventions
Every enumeration in enums.rs follows the same pattern. If modifying or updating to a
new SISO revision, please adhere to this existing pattern so that the file stays consistent
and could be regenerated by a script later.
Ordinary enums
// SISO-REF-010-2023 RepairResponseRepairResult [UID 65]
#[derive(Copy, Clone, Debug, Default, FromPrimitive, PartialEq, Eq)]
pub enum RepairResponseRepairResult {
#[default]
Other = 0,
RepairEnded = 1,
InvalidRepair = 2,
RepairInterrupted = 3,
ServiceCanceledByTheSupplier = 4,
}
impl_deku_enum!(RepairResponseRepairResult, u8, from_u8);
- Comment line. The SISO-REF-010 revision, the table name and its UID. The UID is how anyone can find the table in SISO-REF-010.
- Name. The table name in upper camel case, with spaces and punctuation removed. Variant names follow the same rule, from each row’s description.
- Values. Give every variant an explicit value. Do not allow for values to be determined implicitly.
- Default. Mark the variant for value 0, usually
OtherorNoStatement, with#[default]. If 0 isn’t defined, use the most neutral value. impl_deku_enum!. The second argument is the field’s width on the wire, as given by SISO-REF-010:u8,u16oru32. The third is the matchingFromPrimitivemethod:from_u8,from_u16orfrom_u32. A wrong width shifts every field after it.
Bit flags
Tables whose values are bits that can be combined use bitflags! instead. These, and
the hand-written bit layouts with multi-bit fields, live in src/siso/bit_records.rs
and src/siso/appearance.rs, not in enums.rs, so regenerating enums.rs will not
overwrite them:
// SISO-REF-010-2023 FrozenBehavior [UID 68]
bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct FrozenBehavior: u8 {
const RunSimulationClock = 1 << 0;
const TransmitUpdates = 1 << 1;
const ProcessUpdates = 1 << 2;
}
}
impl_deku_bitflags!(FrozenBehavior, u8);
PDU Status fields
The enums for the PDU Status record’s bit fields, such as LVCIndicator, are packed
into PduStatus by its accessors, which match on every variant. Adding a variant to
one of them is a compile error until the matching accessor handles it.
Deprecated values
When SISO deprecates a value, keep the variant and mark it:
#[deprecated(note = "Deprecated in SISO-REF-010-2023")]
SerbiaandMontenegro_ = 240,
NEVER remove or renumber a variant, even a deprecated one. Old recordings and older simulators still send those values, and the crate needs to be able to decode them.
Moving to a new revision
1. Get the new revision
Download the new SISO-REF-010 from the SISO website. Along with the PDF, SISO publishes a machine-readable XML edition, which is much easier to compare between revisions.
2. Find what changed
Compare the XML of the new revision with the current one, and list the tables that changed. For each one, note any new values, deprecated values and renamed descriptions. Also note any tables that are new in this revision.
3. Update the enums
For each changed table:
- New values: add variants with explicit values in numeric order.
- Newly deprecated values: add
#[deprecated(note = "Deprecated in SISO-REF-010-YYYY")]. - Renamed descriptions: keep the old variant name, because renaming a variant breaks users’ code. If the new name is much clearer, add it as an associated constant instead, and leave the old variant as it is:
impl Country {
#[allow(non_upper_case_globals)]
pub const NewName: Self = Self::OldName;
}
- New tables: add a new enum following the conventions above.
4. Update the tests
src/siso/enums/tests.rs has one line per enum in
deku_matches_from_primitive_for_every_enum. Add a line for every new enum:
check_u8::<RepairResponseRepairResult>(RepairResponseRepairResult::from_u8);
check_u8 and check_u16 test every possible value. check_u32 can’t, so it takes a
list of the defined values, which you must update whenever you add values to a 32-bit
enum:
check_u32::<EntityCapabilities>(
&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
EntityCapabilities::from_u32,
);
5. Update the revision everywhere
Replace the old revision with the new one in
- the comment line above every enum in
enums.rs - the Enumerations page in this book
README.mdwhere the revision is mentioned
Leave the revision in existing #[deprecated] notes as it is. Those record when each
value was deprecated.