Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lucasw opened this issue Jun 23, 2024 · 3 comments
Open

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

lucasw opened this issue Jun 23, 2024 · 3 comments

Comments

@lucasw
Copy link
Owner

lucasw commented Jun 23, 2024

I think I need rosrust for this- or roslibrust?

@lucasw
Copy link
Owner Author

lucasw commented Jun 23, 2024

@lucasw
Copy link
Owner Author

lucasw commented Jun 23, 2024

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

-> #7 (comment)

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

@lucasw
Copy link
Owner Author

lucasw commented Jun 23, 2024

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/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.clone());
msg_with_header.append(&mut message_data);
/*
{
let mut test_msg = marti_common_msgs::Float32Stamped::default();
test_msg.header.seq = 3;
test_msg.header.frame_id = "test".to_string();
test_msg.header.stamp.secs = 1;
test_msg.header.stamp.nsecs = 7;
test_msg.value = 1.0;
let test_data = serde_rosmsg::to_vec(&test_msg).unwrap();
println!("test {} - {:02x?}", test_data.len(), &test_data[..]);
println!("mcap {} - {:02x?}", msg_with_header_vec.len(), &msg_with_header_vec[..]);
}
*/
// match serde_rosmsg::from_slice::<marti_common_msgs::Float32Stamped>(&msg_with_header) {
match serde_rosmsg::from_slice::<nav_msgs::Odometry>(&msg_with_header) {
Ok(odom_msg) => {
println!("{:#?}", odom_msg);


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);
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant