From 8aa957b8bb03ed3d032a44d3323d200fdc610d85 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Aug 2024 16:56:25 +0200 Subject: [PATCH] update msg to user module --- CHANGELOG.md | 2 ++ src/cfdp/tlv/msg_to_user.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7813628..892ac4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). API to the file data buffer without an intermediate buffer. - Generic `EofPdu::new` constructor. - Added generic sequence counter module. +- Added `MsgToUserTlv::to_tlv` converter which reduced the type and converts + it to a generic `Tlv`. ## Added and Changed diff --git a/src/cfdp/tlv/msg_to_user.rs b/src/cfdp/tlv/msg_to_user.rs index c6bb673..1213926 100644 --- a/src/cfdp/tlv/msg_to_user.rs +++ b/src/cfdp/tlv/msg_to_user.rs @@ -78,6 +78,10 @@ impl<'data> MsgToUserTlv<'data> { Ok(msg_to_user) } + pub fn to_tlv(&self) -> Tlv<'data> { + self.tlv + } + #[cfg(feature = "alloc")] pub fn to_owned(&self) -> TlvOwned { self.tlv.to_owned() @@ -146,6 +150,32 @@ mod tests { ); } + #[test] + fn test_msg_to_user_type_reduction() { + let custom_value: [u8; 4] = [1, 2, 3, 4]; + let msg_to_user = MsgToUserTlv::new(&custom_value).unwrap(); + let tlv = msg_to_user.to_tlv(); + assert_eq!( + tlv.tlv_type_field(), + TlvTypeField::Standard(TlvType::MsgToUser) + ); + + assert_eq!(tlv.value(), custom_value); + } + + #[test] + fn test_msg_to_user_owner_converter() { + let custom_value: [u8; 4] = [1, 2, 3, 4]; + let msg_to_user = MsgToUserTlv::new(&custom_value).unwrap(); + let tlv = msg_to_user.to_owned(); + assert_eq!( + tlv.tlv_type_field(), + TlvTypeField::Standard(TlvType::MsgToUser) + ); + + assert_eq!(tlv.value(), custom_value); + } + #[test] fn test_reserved_msg_deserialization() { let custom_value: [u8; 3] = [1, 2, 3];