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:<div><br></div><div>struct A</div>


<div>{</div><div>  char a;</div><div>  int b;</div><div>};</div><div><br></div><div>sizeof(A) == 8 (not 5), and offsetof(A, b) == 4 (not 1) on x64, but may be different on different architectures.</div><div><br></div><div>

If the data is in the ROS serialization format (see the table under built-in types at <a href="http://www.ros.org/wiki/msg#Message_Description_Specification">http://www.ros.org/wiki/msg#Message_Description_Specification</a>), you may be able to use the ROS serialization code (<a href="http://www.ros.org/wiki/roscpp/Overview/MessagesSerializationAndAdaptingTypes">http://www.ros.org/wiki/roscpp/Overview/MessagesSerializationAndAdaptingTypes</a>)</div>

<div><br></div><div>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.</div><div><br></div><div>Josh<br>

<br><div class="gmail_quote">On Thu, Jul 8, 2010 at 4:21 PM, Bill Morris <span dir="ltr"><<a href="mailto:morris@ee.ccny.cuny.edu" target="_blank">morris@ee.ccny.cuny.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am wondering if there is a suggested method for constructing a message<br>
directly from binary data stored in memory.<br>
<br>
Right now I read in data from a serial port into a buffer and once I<br>
have a complete chunk of data I memcpy it into a struct. I then copy<br>
each item in the struct into the message, item by item. I would like to<br>
avoid copying each item individually by name.<br>
<br>
Are the following structs and messages laid out in memory the same way?<br>
Are there byte order or alignment issues I should be aware of if i<br>
attempt to create a message using memcpy?<br>
<br>
Do I want to deserialize or serialize the message? Is there<br>
documentation for this somewhere? Is there a better way to do this?<br>
<br>
    struct IMU<br>
    {<br>
      int angle_nick;<br>
      int angle_roll;<br>
      int angle_yaw;<br>
      short acc_x;<br>
      short acc_y;<br>
      short acc_z;<br>
    };<br>
<br>
IMU.msg<br>
int32 angle_nick<br>
int32 angle_roll<br>
int32 angle_yaw<br>
int16 acc_x<br>
int16 acc_y<br>
int16 acc_z<br>
<br>
<br>
_______________________________________________<br>
ros-users mailing list<br>
<a href="mailto:ros-users@code.ros.org" target="_blank">ros-users@code.ros.org</a><br>
<a href="https://code.ros.org/mailman/listinfo/ros-users" target="_blank">https://code.ros.org/mailman/listinfo/ros-users</a><br>
</blockquote></div><br></div>