1 个不稳定版本

0.1.0 2024年7月10日

#1011解析器实现

MIT 许可协议

70KB
1K SLoC

Srex

Srex 是一个用于解析 SRec 文件的库。

示例

use std::{fs, str::FromStr};
use srex::srecord::SRecordFile;

let srecord_str = fs::read_to_string("path/to/file.s37").unwrap();
let srecord_file = SRecordFile::from_str(&srecord_str).unwrap();

// Get data at address 0x123
let x: u8 = srecord_file[0x123];
println!("Data at address 0x123: {x}");

⚠️ 此工具目前正在构建中,未来提交中可能会有较大变化。


lib.rs:

Srex

用于解析、读取和编辑 Motorola S-Record 文件 中的数据的库。

该库提供了一个简单的接口,用于在特定或地址范围内的读写数据

use std::str::FromStr;
use srex::srecord::SRecordFile;

let mut srecord_file = SRecordFile::from_str("\
    S00F000068656C6C6F202020202000003C\n\
    S321000000007C0802A6900100049421FFF07C6C1B787C8C23783C6000003863000024\n\
    S3210000001C4BFFFFE5398000007D83637880010014382100107C0803A64E800020E7\n\
    S3130000003848656C6C6F20776F726C642E0A0040\n\
    S5030003F9\n\
    S70500000000FA\n\
").unwrap();

// It is possible to access specific addresses:
println!("Data at address 0x1C: {}", srecord_file.get(0x1C).unwrap());
srecord_file[0x1C] = 0xAA;
println!("Data at address 0x1C is now: {}", srecord_file[0x1C]);

// It is also possible to access address ranges:
assert_eq!(srecord_file[0x1C..0x1E], [0xAA, 0xFF]);
for (i, b) in srecord_file.get_mut(0x38..0x3C).unwrap().iter_mut().enumerate() {
    *b = i as u8;
}
assert_eq!(srecord_file[0x38..0x3C], [0x00, 0x01, 0x02, 0x03]);

依赖项

~22KB