Skip to main content

new_atomic_req

Function new_atomic_req 

Source
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. Returns Err(TlpError::UnsupportedCombination) if the packet does not encode one of the three atomic op types, and Err(TlpError::InvalidLength) if the data payload has the wrong size for the expected header and operands.

ยงExamples

use rtlp_lib::{TlpPacket, 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);
let ar = new_atomic_req(&pkt).unwrap();
assert_eq!(ar.req_id(),   0xABCD);
assert_eq!(ar.operand0(), 4);
assert!(ar.operand1().is_none());