pub fn new_atomic_req(
pkt: &TlpPacket,
) -> Result<Box<dyn AtomicRequest>, TlpError>Expand description
Parse an atomic TLP request from a TlpPacket.
The TLP type and format are extracted from the packet header.
§Errors
TlpError::UnsupportedCombinationif the packet does not encode one of the three atomic op types, or if the format field is notWithData3DW/WithData4DW.TlpError::InvalidLengthif the data payload size does not match the expected header + operand(s) size for the detected atomic type and width.
§Examples
use rtlp_lib::{TlpPacket, TlpMode, AtomicRequest, new_atomic_req};
// FetchAdd 3DW: DW0 byte0 = (fmt=0b010 << 5) | typ=0b01100 = 0x4C
let bytes = vec![
0x4C, 0x00, 0x00, 0x00, // DW0: WithDataHeader3DW / FetchAdd
0xAB, 0xCD, 0x01, 0x00, // DW1: req_id=0xABCD tag=1 BE=0
0x00, 0x00, 0x10, 0x00, // DW2: address32=0x0000_1000
0x00, 0x00, 0x00, 0x04, // operand: addend=4
];
let pkt = TlpPacket::new(bytes, TlpMode::NonFlit).unwrap();
let ar = new_atomic_req(&pkt).unwrap();
assert_eq!(ar.req_id(), 0xABCD);
assert_eq!(ar.operand0(), 4);
assert!(ar.operand1().is_none());