added missing ctor

This commit is contained in:
Robin Mueller
2025-12-09 15:18:02 +01:00
parent e5b165def3
commit 42f87dad99

View File

@@ -71,6 +71,12 @@ pub enum UslpError {
ChecksumFailure(u16), ChecksumFailure(u16),
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[error("FHP or LVO field invalid for given construction rule")]
pub struct FhpLvoError(pub ConstructionRule);
/// Invalid value for length. /// Invalid value for length.
#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)] #[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
@@ -374,6 +380,27 @@ pub struct TransferFrameDataFieldHeader {
} }
impl TransferFrameDataFieldHeader { impl TransferFrameDataFieldHeader {
/// Constructor for the transfer frame data field header.
///
/// This constructor also checks whether the passed first header pointer or last valid octet
/// field is compatible to the construction rule.
pub const fn new(
construction_rule: ConstructionRule,
uslp_protocol_id: UslpProtocolId,
fhp_or_lvo: Option<u16>,
) -> Result<Self, FhpLvoError> {
if (construction_rule.applicable_to_fixed_len_tfdz() && fhp_or_lvo.is_none())
|| (!construction_rule.applicable_to_fixed_len_tfdz() && fhp_or_lvo.is_some())
{
return Err(FhpLvoError(construction_rule));
}
Ok(Self {
construction_rule,
uslp_protocol_id,
fhp_or_lvo,
})
}
/// Length of the header when written to bytes. /// Length of the header when written to bytes.
#[inline] #[inline]
pub const fn len_header(&self) -> usize { pub const fn len_header(&self) -> usize {
@@ -1147,11 +1174,11 @@ mod tests {
0, 0,
) )
.unwrap(); .unwrap();
let data_field_header = TransferFrameDataFieldHeader { let data_field_header = TransferFrameDataFieldHeader::new(
construction_rule: ConstructionRule::NoSegmentation, ConstructionRule::NoSegmentation,
uslp_protocol_id: UslpProtocolId::UserDefinedOctetStream, UslpProtocolId::UserDefinedOctetStream,
fhp_or_lvo: None, None,
}; ).unwrap();
let data = [1, 2, 3, 4]; let data = [1, 2, 3, 4];
let mut frame_creator = let mut frame_creator =
TransferFrameCreator::new(primary_header, data_field_header, &data, Some(4), true); TransferFrameCreator::new(primary_header, data_field_header, &data, Some(4), true);