There are two sides to this:
- serialisation of actual message contents to the
stream
(in ros::serialization::Serializer<>::*(..)
), and - message structure definition exchanged by nodes when a connection is setup (ie: msg, srv or action connections)
For the first: no, constants do not get serialised, only message fields. See here for an example of the DiagnosticsStatus.msg
code (from /opt/ros/melodic/include/diagnostic_msgs/DiagnosticStatus.h
, slightly simplified):
namespace serialization
{
template<..> struct Serializer<..>
{
template<..> inline static void allInOne(Stream& stream, T m)
{
stream.next(m.level);
stream.next(m.name);
stream.next(m.message);
stream.next(m.hardware_id);
stream.next(m.values);
}
};
}
Legal values for level
in this case would be one of the values defined by the constants in the message definition (OK
, WARN
, ERROR
or STALE
), but only level
gets serialised.
As for the second: upon subscribing, nodes will negotiate the parameters/configuration of the actual TCP or UDP connection that will be used to exchange message data (ie: the bytes serialised into the stream
in the code shown above, which in the end is a buffer). In that negotation, the complete message definition is exchanged as well and that message definition does contain the constants (see here for TCPROS
). So in this case, they are included.
Negotation takes place only once per connection, so the message definition is exchanged only once as well.