pub struct Pdu { /* private fields */ }Expand description
Modbus Protocol Data Unit (PDU).
The PDU is the core of the Modbus message, consisting of a function code and the associated data payload.
Implementations§
Source§impl Pdu
impl Pdu
Sourcepub fn new(
function_code: FunctionCode,
data: Vec<u8, MAX_PDU_DATA_LEN>,
data_len: u8,
) -> Self
pub fn new( function_code: FunctionCode, data: Vec<u8, MAX_PDU_DATA_LEN>, data_len: u8, ) -> Self
Sourcepub fn function_code(&self) -> FunctionCode
pub fn function_code(&self) -> FunctionCode
Accessor for the function code.
Sourcepub fn error_code(&self) -> Option<u8>
pub fn error_code(&self) -> Option<u8>
Accessor for the error code from the PDU.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8, 253>, MbusError>
pub fn to_bytes(&self) -> Result<Vec<u8, 253>, MbusError>
Converts the PDU into its byte representation.
This method serializes the function code and its associated data payload.
It uses an unsafe block to access the Data union, assuming that
self.data.bytes contains the full data payload and self.data_len
accurately reflects its length.
§Returns
Ok(Vec<u8, 253>) containing the PDU bytes, or an MbusError if
the PDU cannot be serialized (e.g., due to buffer overflow).
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, MbusError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, MbusError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Pdu
impl RefUnwindSafe for Pdu
impl Send for Pdu
impl Sync for Pdu
impl Unpin for Pdu
impl UnsafeUnpin for Pdu
impl UnwindSafe for Pdu
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more