Compare commits
2 Commits
42d3487c19
...
96d389a651
Author | SHA1 | Date | |
---|---|---|---|
96d389a651 | |||
cc680dba46 |
18
src/time.rs
18
src/time.rs
@@ -38,7 +38,7 @@ impl TryFrom<u8> for CcsdsTimeCodes {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub enum TimestampError {
|
||||
/// Contains tuple where first value is the expected time code and the second
|
||||
/// value is the found raw value
|
||||
@@ -71,7 +71,7 @@ pub const fn ccsds_to_unix_days(ccsds_days: i32) -> i32 {
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -194,12 +194,14 @@ impl CcsdsTimeProvider 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() {
|
||||
return Err(PacketError::ToBytesSliceTooSmall(SizeMissmatch {
|
||||
expected: self.len_as_bytes(),
|
||||
found: buf.len(),
|
||||
}));
|
||||
return Err(TimestampError::OtherPacketError(
|
||||
PacketError::ToBytesSliceTooSmall(SizeMissmatch {
|
||||
expected: self.len_as_bytes(),
|
||||
found: buf.len(),
|
||||
}),
|
||||
));
|
||||
}
|
||||
buf[0] = self.pfield;
|
||||
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]);
|
||||
assert!(res.is_err());
|
||||
match res.unwrap_err() {
|
||||
ToBytesSliceTooSmall(missmatch) => {
|
||||
OtherPacketError(ToBytesSliceTooSmall(missmatch)) => {
|
||||
assert_eq!(missmatch.found, i);
|
||||
assert_eq!(missmatch.expected, 7);
|
||||
}
|
||||
|
Reference in New Issue
Block a user