2 Commits

Author SHA1 Message Date
96d389a651 fix test
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good
2022-09-03 16:30:21 +02:00
cc680dba46 timestamp writer should return timestamp error too 2022-09-03 16:28:11 +02:00

View File

@@ -38,7 +38,7 @@ impl TryFrom<u8> for CcsdsTimeCodes {
} }
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum TimestampError { pub enum TimestampError {
/// Contains tuple where first value is the expected time code and the second /// Contains tuple where first value is the expected time code and the second
/// value is the found raw value /// value is the found raw value
@@ -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(
expected: self.len_as_bytes(), PacketError::ToBytesSliceTooSmall(SizeMissmatch {
found: buf.len(), expected: self.len_as_bytes(),
})); 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());
@@ -334,7 +336,7 @@ mod tests {
let res = time_stamper.write_to_bytes(&mut buf[0..i]); let res = time_stamper.write_to_bytes(&mut buf[0..i]);
assert!(res.is_err()); assert!(res.is_err());
match res.unwrap_err() { match res.unwrap_err() {
ToBytesSliceTooSmall(missmatch) => { OtherPacketError(ToBytesSliceTooSmall(missmatch)) => {
assert_eq!(missmatch.found, i); assert_eq!(missmatch.found, i);
assert_eq!(missmatch.expected, 7); assert_eq!(missmatch.expected, 7);
} }