doip_definitions/doip_payload/
alive_check_response.rs1use crate::definitions::DOIP_DIAG_COMMON_SOURCE_LEN;
2use crate::error::{Error, Result};
3
4#[cfg_attr(feature = "python-bindings", pyo3::pyclass)]
8#[derive(Copy, Clone, Debug, PartialEq)]
9pub struct AliveCheckResponse {
10 pub source_address: [u8; DOIP_DIAG_COMMON_SOURCE_LEN],
12}
13
14impl From<AliveCheckResponse> for [u8; DOIP_DIAG_COMMON_SOURCE_LEN] {
15 fn from(value: AliveCheckResponse) -> Self {
16 value.source_address
17 }
18}
19
20impl TryFrom<&[u8]> for AliveCheckResponse {
21 type Error = Error;
22
23 fn try_from(value: &[u8]) -> Result<Self> {
24 let source_address: [u8; DOIP_DIAG_COMMON_SOURCE_LEN] = value
25 .get(0..DOIP_DIAG_COMMON_SOURCE_LEN)
26 .ok_or(Error::OutOfBounds {
27 source: "AliveCheckResponse",
28 variable: "Source Address",
29 })?
30 .try_into()?;
31
32 Ok(AliveCheckResponse { source_address })
33 }
34}