Skip to content

Commit

Permalink
Merge pull request 'update msg to user module' (#107) from cfdp-msg-t…
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Aug 20, 2024
2 parents 190fa1b + 8aa957b commit b19a61b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions src/cfdp/tlv/msg_to_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit b19a61b

Please sign in to comment.