extended time writer trait
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good

This commit is contained in:
2024-02-05 15:04:29 +01:00
parent 92403738ca
commit d01309cccf
5 changed files with 55 additions and 1 deletions

View File

@ -189,9 +189,18 @@ pub fn ms_of_day(seconds_since_epoch: f64) -> u32 {
}
pub trait TimeWriter {
fn len_written(&self) -> usize;
/// Generic function to convert write a timestamp into a raw buffer.
/// Returns the number of written bytes on success.
fn write_to_bytes(&self, bytes: &mut [u8]) -> Result<usize, TimestampError>;
#[cfg(feature = "alloc")]
fn to_vec(&self) -> Result<alloc::vec::Vec<u8>, TimestampError> {
let mut vec = alloc::vec![0; self.len_written()];
self.write_to_bytes(&mut vec)?;
Ok(vec)
}
}
pub trait TimeReader {