You can also use $cast to check if this is true and copy at the same time. Therefore, instead of executing: cmd = my_cmd'(value_from_bus); You can do it:
if ($cast(cmd, value_from_bus)) $display("Valid: %s", cmd.name()); else $display("Invalid");
Example Playground EDA
source share