read_components/
read_components.rs1use brdb::{BrFsReader, BrReader, Brdb, Brz, IntoReader};
2use std::path::PathBuf;
3
4fn run<T: BrFsReader>(db: &BrReader<T>) -> Result<(), Box<dyn std::error::Error>> {
5 println!(
6 "Component types: {:?}",
7 db.global_data()?.component_type_names
8 );
9 println!(
10 "Component structs: {:?}",
11 db.global_data()?.component_data_struct_names
12 );
13 for gid in 1..32 {
16 let chunks = match db.brick_chunk_index(gid) {
17 Ok(c) => c,
18 Err(_) => break,
19 };
20 println!("=== grid {gid} ===");
21 for chunk in chunks {
22 println!(
23 "chunk {} bricks={} components={} wires={}",
24 chunk.index, chunk.num_bricks, chunk.num_components, chunk.num_wires
25 );
26 if chunk.num_components > 0 {
27 match db.component_chunk_soa(gid, chunk.index) {
28 Ok((_soa, components)) => {
29 for c in components {
30 println!(" component: {c}");
31 }
32 }
33 Err(e) => {
34 println!(" ERROR reading components: {e}");
35 return Err(e.into());
36 }
37 }
38 }
39 }
40 }
41 Ok(())
42}
43
44fn main() -> Result<(), Box<dyn std::error::Error>> {
45 let p = PathBuf::from(std::env::args().nth(1).unwrap());
46 if p.extension().and_then(|e| e.to_str()) == Some("brdb") {
47 run(&Brdb::open(&p)?.into_reader())
48 } else {
49 run(&Brz::open(&p)?.into_reader())
50 }
51}