lucasw / ros_one2z

Similar node graphs in vanilla ros1 and ros2 and also zenoh, focus on localhost using python but also C++ and maybe rust
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

decode/deserialize/parse bytes from mcap ros1msg in rust #10

Open lucasw opened 1 week ago

lucasw commented 1 week ago

I think I need rosrust for this- or roslibrust?

lucasw commented 1 week ago

https://github.com/adnanademovic/serde_rosmsg

lucasw commented 1 week ago

Create simple test bag + mcap

rostopic pub /test marti_common_msgs/Float32Stamped  "header:
  seq: 3
  stamp:
    secs: 1
    nsecs: 7
  frame_id: 'test'
value: 1.0" -r 1

The test message is generated internally using the roslibrust message + serde_rosmsg to_vec()

test 28 - [18, 00, 00, 00, 03, 00, 00, 00, 01, 00, 00, 00, 07, 00, 00, 00, 04, 00, 00, 00, 74, 65, 73, 74, 00, 00, 80, 3f]
mcap 24 - [0a, 00, 00, 00, 01, 00, 00, 00, 07, 00, 00, 00, 04, 00, 00, 00, 74, 65, 73, 74, 00, 00, 80, 3f]

It has an extra 4 byte header over the mcap encoded message

-> https://github.com/lucasw/ros_one2z/issues/7#issuecomment-1826426812

https://github.com/adnanademovic/serde_rosmsg/blob/master/src/lib.rs#L13

lucasw commented 1 week ago

It would be nice if serde_rosmsg had from_slice option to not require the header bytes (unless it actually uses them, but it has an array/vector length already)

https://github.com/lucasw/ros_one2z/blob/e79615ae7dd263c19278561b94cce5dc0642a502/mcap_to_rerun/src/main.rs#L43-L66


use roslibrust_codegen_macro::find_and_generate_ros_messages;
find_and_generate_ros_messages!();

...

// https://github.com/adnanademovic/serde_rosmsg/blob/master/src/lib.rs#L9
let len_header = message.data.len() as u32;
let mut msg_with_header = Vec::from(len_header.to_le_bytes());
let mut message_data = Vec::from(message.data);
msg_with_header.append(&mut message_data);
match serde_rosmsg::from_slice::<nav_msgs::Odometry>(&msg_with_header) {
    Ok(odom_msg) => {
        println!("{:#?}", odom_msg);
...