36 lines
921 B
Rust
Raw Normal View History

2023-08-15 21:07:15 +02:00
use derive_new::new;
use satrs::hk::UniqueId;
use satrs::request::UniqueApidTargetId;
use satrs::spacepackets::ByteConversionError;
2023-08-15 21:07:15 +02:00
#[derive(Debug, new, Copy, Clone)]
pub struct HkUniqueId {
target_id: UniqueApidTargetId,
set_id: UniqueId,
2023-08-15 21:07:15 +02:00
}
impl HkUniqueId {
2024-01-30 23:48:46 +01:00
#[allow(dead_code)]
pub fn target_id(&self) -> UniqueApidTargetId {
2024-01-30 23:59:29 +01:00
self.target_id
}
#[allow(dead_code)]
pub fn set_id(&self) -> UniqueId {
2024-01-30 23:59:29 +01:00
self.set_id
2023-08-15 21:07:15 +02:00
}
#[allow(dead_code)]
2024-01-30 23:59:29 +01:00
pub fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {
2023-08-15 21:07:15 +02:00
if buf.len() < 8 {
2024-01-30 23:59:29 +01:00
return Err(ByteConversionError::ToSliceTooSmall {
found: buf.len(),
expected: 8,
});
2023-08-15 21:07:15 +02:00
}
buf[0..4].copy_from_slice(&self.target_id.unique_id.to_be_bytes());
2024-01-30 23:59:29 +01:00
buf[4..8].copy_from_slice(&self.set_id.to_be_bytes());
2023-08-15 21:07:15 +02:00
2024-01-30 23:59:29 +01:00
Ok(8)
2023-08-15 21:07:15 +02:00
}
}