2 unstable releases

Uses old Rust 2015

0.2.0 May 2, 2017
0.1.0 Feb 19, 2017

#51 in #ros

Download history 120/week @ 2024-08-26 92/week @ 2024-09-02 113/week @ 2024-09-09 123/week @ 2024-09-16 167/week @ 2024-09-23 107/week @ 2024-09-30 74/week @ 2024-10-07 97/week @ 2024-10-14 126/week @ 2024-10-21 75/week @ 2024-10-28 38/week @ 2024-11-04 12/week @ 2024-11-11 70/week @ 2024-11-18 7/week @ 2024-11-25 21/week @ 2024-12-02 73/week @ 2024-12-09

172 downloads per month

MIT license

62KB
1.5K SLoC

Serde ROSMSG

MIT Licensed Crates.io Build Status

serde_rosmsg is a Rust serializer to the rosmsg data format, used in TCPROS and UDPROS.

For more information you can look at:

License

serde_rosmsg is distributed under the MIT license.


lib.rs:

Serde ROSMSG

ROSMSG is a binary format used for communication between ROS nodes.

Message types are defined in ROS's own specification. The linked specification contains information about supported data structures. Serialization is performed by just writing the underlying binary data in a Little Endian byte order. Fields that contain multiple items are prefixed with a 32-bit length, in number of items. That applies to variable sized arrays (like vectors) and strings. Serialized data is prefixed by a 32-bit number, representing the number of bytes in the serialized data, excluding that prefix.

Examples

If we wanted to serialize "Rust is great!", we would need to prefix the string with 14, which is the string's length. Then we would need to prefix that with 18, the combined length of the length annotation and the string itself.

let rosmsg_data = to_vec(&String::from("Rust is great!")).unwrap();
assert_eq!(rosmsg_data, b"\x12\0\0\0\x0e\0\0\0Rust is great!");
let rust_data: String = from_slice(&rosmsg_data).unwrap();
assert_eq!(rust_data, "Rust is great!");

Serialization is performed using serde. Thus, if you want to serialize your own structures, you can use serde_derive

extern crate serde_rosmsg;
#[macro_use]
extern crate serde_derive;
use serde_rosmsg::{to_vec, from_slice};

fn main() {
#[derive(Debug,Serialize,Deserialize,PartialEq)]
struct Position {
    x: i16,
    y: i16,
    z: i16,
}

let data = Position {
    x: 1025,
    y: -1,
    z: 5,
};

let rosmsg_data = to_vec(&data).unwrap();
assert_eq!(rosmsg_data, [6, 0, 0, 0, 1, 4, 255, 255, 5, 0]);
let rust_data: Position = from_slice(&rosmsg_data).unwrap();
assert_eq!(rust_data, data);
}

Dependencies

~2.9–8.5MB
~92K SLoC