Skip to content

amin-abouee/rosbags-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

rosbags-rs

CI Crates.io Documentation License

A high-performance Rust library for reading and writing ROS2 bag files with full Python rosbags compatibility. This library provides comprehensive functionality to read and write ROS2 bag files in both SQLite3 and MCAP formats, with guaranteed byte-for-byte identical results compared to the Python rosbags library.

๐Ÿš€ Features

  • โœ… Complete ROS2 bag reading and writing - SQLite3 and MCAP formats
  • โœ… 94+ ROS2 message types - Full support across all major categories
  • โœ… Python rosbags compatibility - Byte-for-byte identical results
  • โœ… High performance - Zero-copy message reading where possible
  • โœ… Comprehensive CDR deserialization - All standard ROS2 message types
  • โœ… Advanced filtering - By topic, time range, and message type
  • โœ… Compression support - zstd compressed bags
  • โœ… Type-safe error handling - Comprehensive error types
  • โœ… Self-contained tests - No external dependencies required
  • โœ… Production ready - Extensive test coverage and CI/CD

๐ŸŽฏ Supported ROS2 Versions

  • ROS2 Jazzy Jalopy (LTS)
  • ROS2 Humble Hawksbill (LTS)
  • ROS2 Foxy Fitzroy (LTS)

๐Ÿ“ฆ Installation

Add this to your Cargo.toml:

[dependencies]
rosbags-rs = "0.2.0"

๐Ÿ”ง Command Line Tools

This library includes several command-line utilities for working with ROS2 bag files:

bag_filter - Copy and filter bag files

High-performance bag copying with topic and time filtering:

# Copy entire bag
cargo run --bin bag_filter -- /path/to/input_bag /path/to/output_bag

# Copy specific topics only
cargo run --bin bag_filter -- /path/to/input_bag /path/to/output_bag --topics /imu/data,/camera/image_raw

# Copy with time filtering
cargo run --bin bag_filter -- /path/to/input_bag /path/to/output_bag --start 1000000000 --end 2000000000

# List available topics
cargo run --bin bag_filter -- /path/to/input_bag /path/to/output_bag --list-topics

# Use verbose output
cargo run --bin bag_filter -- /path/to/input_bag /path/to/output_bag --verbose

bag_info - Display bag information

Show metadata and statistics about bag files:

cargo run --bin bag_info -- /path/to/rosbag2_directory

extract_topic_data - Extract topic data to files

Extract specific topic data and save to appropriate file formats:

cargo run --bin extract_topic_data -- /path/to/bag /topic_name /output/directory

write_dummy_bag - Create test bags

Generate test bag files with sample data for testing:

cargo run --bin write_dummy_bag -- /path/to/output_bag

๐Ÿ—‚๏ธ Supported ROS2 Bag Formats

Storage Formats

  • โœ… SQLite3 - Primary storage format for ROS2 bags
  • โœ… MCAP - Modern container format with high performance

Compression

  • โœ… None - Uncompressed bags
  • โœ… zstd - File-level and message-level compression
  • โŒ lz4 - Not currently supported

Bag Versions

  • โœ… Version 1-9 - All current ROS2 bag versions supported

๐Ÿ—๏ธ Architecture

The library is structured into several modules:

  • reader - Main Reader struct for opening and reading bags
  • writer - Main Writer struct for creating and writing bags
  • metadata - Parsing and validation of metadata.yaml files
  • storage - Storage backend implementations (SQLite3, MCAP)
  • types - Core data structures (Connection, Message, TopicInfo, etc.)
  • error - Comprehensive error handling
  • cdr - CDR message deserialization
  • messages - ROS2 message type definitions

๐Ÿ›ก๏ธ Error Handling

The library uses the thiserror crate for structured error handling:

use rosbags_rs::{Reader, ReaderError};

match Reader::new("/path/to/bag") {
    Ok(reader) => { /* success */ },
    Err(ReaderError::BagNotFound { path }) => {
        eprintln!("Bag not found: {}", path.display());
    },
    Err(ReaderError::UnsupportedVersion { version }) => {
        eprintln!("Unsupported bag version: {}", version);
    },
    Err(e) => {
        eprintln!("Other error: {}", e);
    }
}

๐Ÿ“Š Supported ROS2 Message Types

This library supports 94+ ROS2 message types across all major categories:

Core Message Categories

  • ๐Ÿ“ก std_msgs - Standard message types (String, Header, etc.)
  • ๐Ÿ“ geometry_msgs - Geometric primitives (Point, Pose, Transform, etc.)
  • ๐Ÿค– sensor_msgs - Sensor data (Image, PointCloud2, Imu, NavSatFix, etc.)
  • ๐Ÿ—บ๏ธ nav_msgs - Navigation messages (Odometry, Path, etc.)
  • ๐Ÿ”ง diagnostic_msgs - System diagnostics
  • โฐ builtin_interfaces - Time and duration types

Cross-Compatibility Guarantee

This Rust implementation provides 100% compatibility with the Python rosbags library:

Feature Python rosbags rosbags-rs
SQLite3 reading โœ… โœ…
MCAP reading โœ… โœ…
SQLite3 writing โœ… โœ…
MCAP writing โœ… โœ…
CDR deserialization โœ… โœ…
Message filtering โœ… โœ…
Compression support โœ… โœ…
Type safety โŒ โœ…
Memory safety โŒ โœ…
Performance Good Excellent
Cross-validation N/A Byte-for-byte identical

๐Ÿš€ Performance

  • Zero-copy message reading where possible
  • Optimized SQL queries for SQLite3 backend
  • SIMD-accelerated parsing for MCAP backend (future work)
  • Lazy-loading of message data - only read what you need
  • Minimal memory allocations - focus on performance and efficiency
  • Bulk operations - Batch reading and writing for maximum throughput

The library is designed for high-throughput applications where performance is critical. The bag_filter tool uses optimized raw copying by default, similar to ros2 bag convert, for maximum speed.

๐Ÿงช Testing

This library includes a comprehensive test suite that validates correctness against the Python rosbags library. All tests are self-contained and do not require an external ROS2 installation.

Running Tests

cargo test -- --nocapture

The tests cover:

  • Unit tests for individual modules
  • Integration tests for reading complete bag files
  • Compatibility tests to ensure byte-for-byte identical results with Python rosbags
  • Fuzz testing to uncover edge cases and potential panics

Test Data

The test bags are generated using the generate_test_bags.py script and are included in the repository.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

Development Setup

  1. Clone the repository
  2. Install Rust: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  3. Build the project: cargo build
  4. Run tests: cargo test

Code Style

This project uses rustfmt for code formatting and clippy for linting. Please ensure your contributions are formatted and free of warnings.

cargo fmt
cargo clippy -- -D warnings

๐Ÿ“œ License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

About

A Rust library for reading ROS2 bag files, inspired by the Python [rosbags](https://gitlab.com/ternaris/rosbags) library.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

โšก