srec-rs

Crates.iosrec-rs
lib.rssrec-rs
version0.1.4
created_at2025-04-28 06:15:39.837072+00
updated_at2025-06-16 04:42:49.468945+00
descriptionsrec crate in Rust
homepage
repositoryhttps://github.com/TuEmb/srec-rs.git
max_upload_size
id1651870
size358,859
Tu Nguyen (TuEmb)

documentation

README

srec-rs

A Rust library for parsing Motorola S-Record (SREC) files and extracting memory layout and data regions.

Features

  • Parse SREC files (S0, S1, S2, S3, S5, S7, S8, S9 records)
  • Validate checksums
  • Extract all data bytes from S1/S2/S3 records
  • Build memory layout regions, merging adjacent/overlapping regions up to a configurable maximum size
  • Simple API for accessing header, memory layout, and data

Usage

Add to your Cargo.toml:

[dependencies]
srec-rs = { path = "." }

Example

use std::fs::File;
use srec_rs::SRecord;

fn main() {
    let file = File::open("test_data/test.srec").expect("Failed to open file");
    let srec = SRecord::<0x8000>::from_srec(file);

    // Print header if present
    if let Some(header) = srec.get_header() {
        println!("Header: {}", header);
    }

    // Print memory layout
    for (addr, size) in srec.get_data_memory_layout() {
        println!("Region: {:?}, size: {:#X}", addr, size);
    }

    // Access raw data
    let data = srec.get_data();
    println!("Total data length: {}", srec.get_data_length());
}

Testing

To run tests and see debug output:

cargo test -- --nocapture

License

This project is licensed under the MIT License. See LICENSE-MIT for details.


Author: TuEmb
Year: 2025

Commit count: 0

cargo fmt