class documentation

class Enum(Projection):

View In Hierarchy

A message walked as usual, with named integer fields rendered as enumerations.

Naming the values of a ROS2 constant set mints a DataType the client can browse, instead of leaving it a bare number whose meaning lives in a .msg file. The rest of the message is the generic walk, and the number is what goes back on a write, so the recipe inverts.

Method decode Read the payload as usual: an enumeration's value is the integer that was sent.
Method shape Walk the message, with an enumeration variable where a field was named.
Instance Variable fields For each ROS2 field name, the label of each value it may carry. The keys are the ROS2 constants themselves, so a set that starts at 1 or skips a number stays correct.
Property inverse Return the walk's inverse, which naming values does not take away.
Method _datatype_name Return the DataType's browse name, qualified by the Component.
Method _overrides Return the enumeration variable of each named field.
Method _require_an_integer_field Return True for a field that can carry an enumeration, and refuse one that cannot.
def decode(self, message: Message, context: ProjectionContext) -> Mapping[str, object]:

Read the payload as usual: an enumeration's value is the integer that was sent.

def shape(self, message_type: type[Message], context: ProjectionContext) -> tuple[PlanEntry, ...]:

Walk the message, with an enumeration variable where a field was named.

fields: Mapping[str, Mapping[int, str]] =

For each ROS2 field name, the label of each value it may carry. The keys are the ROS2 constants themselves, so a set that starts at 1 or skips a number stays correct.

@property
inverse: EncodeFunction | None =

Return the walk's inverse, which naming values does not take away.

def _datatype_name(self, context: ProjectionContext, field_name: str) -> str:

Return the DataType's browse name, qualified by the Component.

DataTypes live in the server-wide address space, while registries are per Component.

def _overrides(self, message_type: type[Message], context: ProjectionContext) -> Mapping[str, PlanEntry]:

Return the enumeration variable of each named field.

def _require_an_integer_field(self, message_type: type[Message], field_name: str) -> bool:

Return True for a field that can carry an enumeration, and refuse one that cannot.

Raises
UnprojectableFieldErrorWhen the field is absent, or is not a single integer.