ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You might not need to iterate the msg fields recursively in the first place. It should be sufficient to iterate only the fields of the current message and for non-builtin field type invoke the serialization / deserialization function of the sub message (rather then implement it again within this message). At least that is the way gencpp, genpy and genlisp deal with it.

You might not need to iterate the msg fields recursively in the first place. It should be sufficient to iterate only the fields of the current message and for non-builtin field type invoke the serialization / deserialization function of the sub message (rather then implement it again within this message). At least that is the way gencpp, genpy and genlisp deal with it.

Update:

Pointing you to code might not be the best help since the message generator code / templates are everything but easy to read. You could look at the gencpp and genpy packages though.

What I am referring to is the following idea: for each built-in type you will have e.g. a serialize function:

serialize(bool)
serialize(int)

When you now want to serialize a Message Foo you will serialize all of its members like this:

serialize(Foo) {
    serialize(my_bool_member)
    serialize(my_int_member)
}

For a nested message you also only care about its member and not about their recursive fields because you will delegate the serialization of sub messages to there existing serialize implementation:

serialize(Bar) {
    serialize(my_foo_member)
    serialize(my_other_foo_member)
}