Skip to main content

new_mem_req

Function new_mem_req 

Source
pub fn new_mem_req(
    bytes: impl Into<Vec<u8>>,
    format: &TlpFmt,
) -> Result<Box<dyn MemRequest>, TlpError>
Expand description

Obtain Memory Request trait from bytes in vector as dyn. This is the preferred way of dealing with TLP headers when the exact format (32-bit vs 64-bit) does not need to be known at the call site.

§Errors

§Examples

use rtlp_lib::TlpPacket;
use rtlp_lib::TlpFmt;
use rtlp_lib::TlpError;
use rtlp_lib::TlpMode;
use rtlp_lib::MemRequest;
use rtlp_lib::new_mem_req;

fn decode(bytes: Vec<u8>) -> Result<(), TlpError> {
    let tlp = TlpPacket::new(bytes, TlpMode::NonFlit)?;

    let tlpfmt = tlp.tlp_format()?;
    // MemRequest contains only fields specific to PCI Memory Requests
    let mem_req: Box<dyn MemRequest> = new_mem_req(tlp.data(), &tlpfmt)?;

    // Address is 64 bits regardless 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.tlp_type());
    Ok(())
}