Skip to content

Commit

Permalink
Merge pull request 'Added additional converter method' (#108) from ms…
Browse files Browse the repository at this point in the history
…gs-to-user-converter-method into main

Reviewed-on: https://egit.irs.uni-stuttgart.de/rust/spacepackets/pulls/108
  • Loading branch information
robamu committed Aug 21, 2024
2 parents b19a61b + 43c88da commit cd77b80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added generic sequence counter module.
- Added `MsgToUserTlv::to_tlv` converter which reduced the type and converts
it to a generic `Tlv`.
- Implemented `From<MsgToUserTlv> for Tlv` converter trait.

## Added and Changed

Expand Down
14 changes: 14 additions & 0 deletions src/cfdp/tlv/msg_to_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ impl<'data> MsgToUserTlv<'data> {
}
}

impl<'a> From<MsgToUserTlv<'a>> for Tlv<'a> {
fn from(value: MsgToUserTlv<'a>) -> Tlv<'a> {
value.to_tlv()
}
}

impl WritableTlv for MsgToUserTlv<'_> {
fn len_written(&self) -> usize {
self.len_full()
Expand Down Expand Up @@ -163,6 +169,14 @@ mod tests {
assert_eq!(tlv.value(), custom_value);
}

#[test]
fn test_msg_to_user_to_tlv() {
let custom_value: [u8; 4] = [1, 2, 3, 4];
let msg_to_user = MsgToUserTlv::new(&custom_value).unwrap();
let tlv: Tlv = msg_to_user.into();
assert_eq!(msg_to_user.to_tlv(), tlv);
}

#[test]
fn test_msg_to_user_owner_converter() {
let custom_value: [u8; 4] = [1, 2, 3, 4];
Expand Down

0 comments on commit cd77b80

Please sign in to comment.