This tutorial demonstrates how to parse MCAP bag files using indexing to achieve 75x faster performance compared to sequential parsing. It walks through parsing footer records, summary offsets, chunk indexes, and message indexes to efficiently extract specific topic messages from ROS2 bag files. The implementation uses Haskell's Megaparsec library with custom monad stacks (StateT, ReaderT, ExceptT) to manage file seeking and state. The approach works with uncompressed chunks and shows how to navigate the MCAP format's index structure to jump directly to desired messages rather than reading the entire file sequentially.
Table of contents
The PlanStep 1 - Parsing the FooterStep 2 - Parsing Summary OffsetsStep 3 - Summary Schemas and ChannelsStep 4 - Chunk Index ProcessingSteps 5 & 6 - Processing Message Indexes and MessagesCompression DisclaimerPulling it TogetherConclusionSort: