Ask Your Question
0

Message size with defined constants

asked 2019-07-08 16:50:39 -0600

jwin gravatar image

Hi all. Was just wondering if message enum constants get included in the message size. For example, if I have a message that has a uint8 constant defined to be 1 and then the actual uint8 payload, would the message take up 8 bits or 16 bits?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2019-07-09 02:30:40 -0600

gvdhoorn gravatar image

updated 2019-07-09 02:36:23 -0600

There are two sides to this:

  1. serialisation of actual message contents to the stream (in ros::serialization::Serializer<>::*(..)), and
  2. 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.

edit flag offensive delete link more

Comments

Ah I see that's perfect then since the network bandwidth will only consist of the actual payload (except for the initial negotiation setup). Thank you and great answer as always.

jwin gravatar imagejwin ( 2019-07-09 03:55:33 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2019-07-08 16:50:39 -0600

Seen: 24 times

Last updated: Jul 09