Re: [ros-users] Message construction with memcpy

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Bill Morris
Date:  
To: Josh Faust
CC: ros-users
Subject: Re: [ros-users] Message construction with memcpy
On Thu, 2010-07-08 at 17:22 -0700, Josh Faust wrote:
> Using memcpy is not possible right now due to the Message base class
> (which is going away in the future). Even once that's gone though
> it's unlikely to work for most messages. For example:
>
>
> struct A
> {
> char a;
> int b;
> };
>
>
> sizeof(A) == 8 (not 5), and offsetof(A, b) == 4 (not 1) on x64, but
> may be different on different architectures.


struct FOO
{
uint16_t x;
int32_t k;
};

I suppose something like this will also have alignment issues.

> If the data is in the ROS serialization format (see the table under
> built-in types
> at http://www.ros.org/wiki/msg#Message_Description_Specification), you
> may be able to use the ROS serialization code
> (http://www.ros.org/wiki/roscpp/Overview/MessagesSerializationAndAdaptingTypes)
>
>
> Unless you're doing this for a large number of devices/messages, it's
> probably easiest (and least brittle) to read the individual values
> manually into the message.


Right now I have 8 messages types and about 100 values total, so I would
like a better solution. I'll take a look at deserializing the objects.

Do I have to worry about endianness when using the serialization code?