timestamp writer should return timestamp error too

This commit is contained in:
Robin Müller 2022-09-03 16:28:11 +02:00
parent 42d3487c19
commit cc680dba46
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C

View File

@ -71,7 +71,7 @@ pub const fn ccsds_to_unix_days(ccsds_days: i32) -> i32 {
} }
pub trait TimeWriter { pub trait TimeWriter {
fn write_to_bytes(&self, bytes: &mut [u8]) -> Result<(), PacketError>; fn write_to_bytes(&self, bytes: &mut [u8]) -> Result<(), TimestampError>;
} }
pub trait TimeReader { pub trait TimeReader {
@ -194,12 +194,14 @@ impl CcsdsTimeProvider for CdsShortTimeProvider {
} }
impl TimeWriter for CdsShortTimeProvider { impl TimeWriter for CdsShortTimeProvider {
fn write_to_bytes(&self, buf: &mut [u8]) -> Result<(), PacketError> { fn write_to_bytes(&self, buf: &mut [u8]) -> Result<(), TimestampError> {
if buf.len() < self.len_as_bytes() { if buf.len() < self.len_as_bytes() {
return Err(PacketError::ToBytesSliceTooSmall(SizeMissmatch { return Err(TimestampError::OtherPacketError(
PacketError::ToBytesSliceTooSmall(SizeMissmatch {
expected: self.len_as_bytes(), expected: self.len_as_bytes(),
found: buf.len(), found: buf.len(),
})); }),
));
} }
buf[0] = self.pfield; buf[0] = self.pfield;
buf[1..3].copy_from_slice(self.ccsds_days.to_be_bytes().as_slice()); buf[1..3].copy_from_slice(self.ccsds_days.to_be_bytes().as_slice());