Skip to content

Conversation

@digizeph
Copy link
Member

@digizeph digizeph commented Dec 8, 2025

This pull request introduces significant improvements to MRT record handling, especially for debugging and raw data export. The changes include a breaking update to the RawMrtRecord struct, new methods for exporting and inspecting raw MRT bytes, enhanced CLI output options, and new example programs demonstrating these features. Additionally, human-readable Display implementations for key MRT types have been added to aid debugging.

Breaking changes and API improvements

  • RawMrtRecord struct update: The raw_bytes field is renamed to message_bytes for clarity, and a new header_bytes field is added to store the raw header bytes. The raw_bytes() method now returns the complete MRT record (header + body) without re-encoding. [1] [2]
  • MRT header parsing: The parser now exposes parse_common_header_with_bytes to return both the parsed header and its raw bytes, enabling exact preservation and export of original MRT records. [1] [2] [3] [4] [5]
  • New methods and tests: Added methods to RawMrtRecord for exporting raw bytes, calculating total length, and extensive tests for header parsing and byte preservation. [1] [2]

Debugging and output enhancements

  • Human-readable output: Implemented Display for MrtRecord, CommonHeader, and MrtMessage, allowing for concise debug output of records and messages. [1] [2] [3]
  • CLI improvements: Added --level (elems or records) and --format (default, json, json-pretty, psv) options for granular and structured output, including full JSON export of records for debugging.

New examples and documentation

  • New examples: Added mrt_debug.rs to demonstrate debug output and raw byte export, and extract_problematic_records.rs to find and export records that fail to parse. [1] [2]
  • Documentation updates: Updated examples/README.md to include new debugging and analysis examples.

These changes greatly improve the ability to debug, analyze, and export MRT records, making it easier to identify and investigate problematic data.Breaking change: RawMrtRecord::raw_bytes renamed to message_bytes and a new header_bytes field was added. The raw_bytes() method now returns the complete MRT record bytes (header + body) without re-encoding. Also add raw-byte helpers, Display implementations, CLI --level/--format options, and examples mrt_debug and extract_problematic_records

Breaking change: RawMrtRecord::raw_bytes renamed to message_bytes and a
new header_bytes field was added. The raw_bytes() method now returns the
complete MRT record bytes (header + body) without re-encoding. Also add
raw-byte helpers, Display implementations, CLI --level/--format options,
and examples mrt_debug and extract_problematic_records
@digizeph digizeph linked an issue Dec 8, 2025 that may be closed by this pull request
3 tasks
@digizeph digizeph requested a review from Copilot December 8, 2025 03:39
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 91.14391% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.50%. Comparing base (e335234) to head (4eb290c).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/models/mrt/mod.rs 71.08% 24 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main     #255    +/-   ##
========================================
  Coverage   90.50%   90.50%            
========================================
  Files          81       81            
  Lines       13006    13260   +254     
========================================
+ Hits        11771    12001   +230     
- Misses       1235     1259    +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds comprehensive debugging and raw byte export capabilities for MRT records, making it easier to identify and analyze problematic data. The changes include breaking API improvements to RawMrtRecord for better clarity, new helper methods for exporting raw bytes, human-readable Display implementations for MRT types, enhanced CLI options for record-level output, and new example programs demonstrating these debugging features.

Key changes:

  • Breaking change: RawMrtRecord.raw_bytes field renamed to message_bytes, with new header_bytes field and raw_bytes() method for complete record export
  • New debugging methods: write_raw_bytes(), append_raw_bytes(), total_bytes_len() on RawMrtRecord
  • CLI enhancements: new --level and --format options for granular output control (elements vs records, various formats)

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/parser/mrt/mrt_record.rs Breaking change to RawMrtRecord struct (field rename), added raw byte export methods, comprehensive tests, and updated usage of new header parsing API
src/parser/mrt/mrt_header.rs New ParsedHeader struct and parse_common_header_with_bytes() function to preserve raw header bytes alongside parsed data, with tests
src/models/mrt/mod.rs Added Display implementations for CommonHeader, MrtRecord, and MrtMessage for human-readable pipe-delimited debug output, with tests
src/bin/main.rs New OutputFormat and OutputLevel enums, updated CLI arguments, and refactored output logic to support record-level and multi-format output
examples/mrt_debug.rs New example demonstrating debug features: JSON output, Display formatting, and raw byte export with verification
examples/extract_problematic_records.rs New example for finding and exporting problematic MRT records that fail to parse
examples/README.md Documentation for the two new debugging and analysis examples
tests/raw_iter.rs Updated tests to use new total_bytes_len() method instead of accessing raw_bytes field directly
CHANGELOG.md Comprehensive documentation of breaking changes and new features

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Export a few records to demonstrate the functionality
let parser = BgpkitParser::new(url).unwrap();
let output_file = "/tmp/debug_records.mrt";
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using hardcoded /tmp/ path is not cross-platform compatible and will fail on Windows. Consider using std::env::temp_dir() or a library like tempfile to create a temporary file path that works across all platforms.

Example:

let output_file = std::env::temp_dir().join("debug_records.mrt");

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@digizeph digizeph merged commit 89fdab7 into main Dec 8, 2025
3 checks passed
@digizeph digizeph deleted the feature/better-debug-output branch December 8, 2025 03:47
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

Successfully merging this pull request may close these issues.

[feature] Debug mode for parser CLI

2 participants