ros2msg - ROS2 Message Parser for Rust
A standalone Rust library for parsing ROS2 message, service, and action files. This crate provides comprehensive functionality to parse .msg, .srv, and .action files according to the ROS2 IDL specification, with support for MSG/SRV/Action to IDL conversion.
This crate can be used independently in any Rust project that needs to work with ROS2 interface definitions, whether you're building code generators, analysis tools, documentation systems, or full ROS2 applications.
Features
- Message parsing: Parse
.msgfiles with support for primitive types, arrays, and constants - Service parsing: Parse
.srvfiles with request/response separation - Action parsing: Parse
.actionfiles with goal/result/feedback sections - IDL conversion: Convert MSG/SRV/Action files to IDL format (compatible with
rosidl_adapter) - Serde support: Optional serialization support with the
serdefeature
Installation
Add this to your Cargo.toml:
[]
= "0.1"
# Enable serde support (optional)
= { = "0.1", = ["serde"] }
Quick Start
use *;
// Parse a message
let msg_content = r#"
# A simple Point message
float64 x # X coordinate [m]
float64 y # Y coordinate [m]
float64 z # Z coordinate [m]
"#;
let msg_spec = parse_message_string?;
println!;
println!;
// Parse a service
let srv_content = r#"
# Add two integers
int64 a
int64 b
---
int64 sum
"#;
let srv_spec = parse_service_string?;
println!;
println!;
// Parse an action
let action_content = r#"
# Fibonacci sequence action
int32 order
---
int32[] sequence
---
int32[] partial_sequence
"#;
let action_spec = parse_action_string?;
println!;
Supported Types
Primitive Types
bool- Boolean valuesbyte,char,uint8- 8-bit unsigned integersint8- 8-bit signed integersuint16,int16- 16-bit integersuint32,int32- 32-bit integersuint64,int64- 64-bit integersfloat32,float64- Floating point numbersstring,wstring- String typesduration,time- Time-related types
Array Types
// Dynamic arrays
int32 numbers
// Fixed-size arrays
int32 fixed_numbers
// Bounded arrays (upper limit)
int32 bounded_numbers
// String bounds
Complex Types
// Message references
geometry_msgs/Point position
// Arrays of complex types
geometry_msgs/Point waypoints
sensor_msgs/LaserScan scans
Constants
// Primitive constants
int32 MAX_SIZE=100
float64 PI=3.14159
string DEFAULT_NAME="robot"
bool DEBUG_MODE=true