This changes where the validation of the field happens to so that the validity of MESSAGE and PRIORITY can be asserted during tests, rather than in each run of add_field_and_payload.
To make this a little more explicit, this changes introduces ValidField as a helper struct for the interface on add_field_and_payload. ValidField is constructed primarily by calling it's validate function, which returns None if the field is invalid. It also has an unchecked function that effectively breaks this guarantee, under the assumption that validate_unchecked will be called during tests. This pair allows for ValidField to be const.
This changes where the validation of the field happens to so that the validity of MESSAGE and PRIORITY can be asserted during tests, rather than in each run of add_field_and_payload.
To make this a little more explicit, this changes introduces ValidField as a helper struct for the interface on add_field_and_payload. ValidField is constructed primarily by calling it's
validate
function, which returns None if the field is invalid. It also has anunchecked
function that effectively breaks this guarantee, under the assumption thatvalidate_unchecked
will be called during tests. This pair allows for ValidField to beconst
.