add a few owned converters
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good
Rust/spacepackets/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2024-06-05 15:34:43 +02:00
parent 92a7bcdc12
commit e0cd096460
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 23 additions and 1 deletions

View File

@ -358,7 +358,7 @@ impl EntityIdTlv {
Ok(Self { entity_id })
}
/// Convert to a generic [Tlv], which also erases the programmatic type information.
/// Convert to a generic [Tlv], which also erases the type information.
pub fn to_tlv(self, buf: &mut [u8]) -> Result<Tlv, ByteConversionError> {
Self::len_check(buf)?;
self.entity_id
@ -369,6 +369,11 @@ impl EntityIdTlv {
_ => panic!("unexpected TLV error"),
})
}
#[cfg(feature = "alloc")]
pub fn to_owned(&self) -> TlvOwned {
TlvOwned::new(TlvType::EntityId, &self.entity_id.to_vec())
}
}
impl WritableTlv for EntityIdTlv {
@ -612,6 +617,11 @@ impl<'first_name, 'second_name> FilestoreRequestTlv<'first_name, 'second_name> {
},
})
}
#[cfg(feature = "alloc")]
pub fn to_owned(&self) -> TlvOwned {
TlvOwned::new(TlvType::FilestoreRequest, &self.to_vec()[2..])
}
}
impl WritableTlv for FilestoreRequestTlv<'_, '_> {
@ -797,6 +807,11 @@ impl<'first_name, 'second_name, 'fs_msg> FilestoreResponseTlv<'first_name, 'seco
filestore_message,
})
}
#[cfg(feature = "alloc")]
pub fn to_owned(&self) -> TlvOwned {
TlvOwned::new(TlvType::FilestoreResponse, &self.to_vec()[2..])
}
}
impl WritableTlv for FilestoreResponseTlv<'_, '_, '_> {

View File

@ -1,4 +1,6 @@
//! Abstractions for the Message to User CFDP TLV subtype.
#[cfg(feature = "alloc")]
use super::TlvOwned;
use super::{GenericTlv, ReadableTlv, Tlv, TlvLvError, TlvType, TlvTypeField, WritableTlv};
use crate::ByteConversionError;
use delegate::delegate;
@ -75,6 +77,11 @@ impl<'data> MsgToUserTlv<'data> {
}
Ok(msg_to_user)
}
#[cfg(feature = "alloc")]
pub fn to_owned(&self) -> TlvOwned {
self.tlv.to_owned()
}
}
impl WritableTlv for MsgToUserTlv<'_> {