pub fn new_mem_req(bytes: Vec<u8>, format: &TlpFmt) -> Box<dyn MemRequest>
Expand description
Obtain Memory Request trait from bytes in vector as dyn This is preffered way of dealing with TLP headers as exact format (32/64 bits) is not required
ยงExamples
use std::convert::TryFrom;
use rtlp_lib::TlpPacket;
use rtlp_lib::TlpFmt;
use rtlp_lib::MemRequest;
use rtlp_lib::new_mem_req;
let bytes = vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
let tlp = TlpPacket::new(bytes);
if let Ok(tlpfmt) = TlpFmt::try_from(tlp.get_tlp_format()) {
// MemRequest contain only fields specific to PCI Memory Requests
let mem_req: Box<dyn MemRequest> = new_mem_req(tlp.get_data(), &tlpfmt);
// Address is 64 bits regardles of TLP format
//println!("Memory Request Address: {:x}", mem_req.address());
// Format of TLP (3DW vs 4DW) is stored in the TLP header
println!("This TLP size is: {}", tlpfmt);
// Type LegacyIO vs MemRead vs MemWrite is stored in first DW of TLP
println!("This TLP type is: {}", tlp.get_tlp_type());
}