Skip to content

Commit 76442f0

Browse files
committed
pldm-platform: Add example PDR Decoder
Can decode standalone dumps for debugging, with deku trace enabled. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
1 parent ec69631 commit 76442f0

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pldm-platform/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ num-derive = { workspace = true }
1717
num-traits = { workspace = true }
1818
pldm = { workspace = true }
1919

20+
[dev-dependencies]
21+
deku = { workspace = true, features = ["logging"] }
22+
env_logger = { workspace = true }
23+
2024
[features]
2125
default = ["std"]
2226
alloc = ["pldm/alloc", "deku/alloc"]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Decode a single Get PDR Response
2+
//!
3+
//! This has basic handling, see requester.rs for a real implementation.
4+
5+
use pldm_platform::deku::DekuContainerRead;
6+
use pldm_platform::proto::*;
7+
8+
use log::*;
9+
10+
fn main() {
11+
env_logger::init();
12+
13+
let a: Vec<_> = std::env::args().collect();
14+
let f = a.get(1).expect("Need input file argument");
15+
println!("loading {f}");
16+
let d = std::fs::read(f).unwrap();
17+
18+
let ((rest, _), pdrrsp) = GetPDRResp::from_bytes((&d, 0))
19+
.map_err(|e| {
20+
println!("GetPDR parse error {e:?}");
21+
panic!("Bad GetPDR response")
22+
})
23+
.unwrap();
24+
println!("rsp {pdrrsp:?}");
25+
assert!(rest.len() == 0);
26+
27+
let ((rest, _), pdr) = Pdr::from_bytes((&pdrrsp.record_data, 0))
28+
.map_err(|e| {
29+
trace!("GetPDR parse error {e}");
30+
panic!("Bad GetPDR response")
31+
})
32+
.unwrap();
33+
if !rest.is_empty() {
34+
panic!("Extra PDR response");
35+
}
36+
assert!(rest.len() == 0);
37+
38+
println!("PDR {pdr:?}");
39+
}

0 commit comments

Comments
 (0)