finish FS request unittests
Some checks failed
Rust/spacepackets/pipeline/pr-main There was a failure building this commit
Rust/spacepackets/pipeline/head There was a failure building this commit

This commit is contained in:
2023-07-02 17:18:33 +02:00
parent 3727e7e668
commit a313a784ff
2 changed files with 109 additions and 7 deletions

View File

@ -1,6 +1,7 @@
//! Generic CFDP length-value (LV) abstraction as specified in CFDP 5.1.8.
use crate::cfdp::TlvLvError;
use crate::{ByteConversionError, SizeMissmatch};
use core::str::Utf8Error;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "std")]
@ -95,6 +96,13 @@ impl<'data> Lv<'data> {
self.data
}
/// Convenience function to extract the value as a [str]. This is useful if the LV is
/// known to contain a [str], for example being a file name.
pub fn value_as_str(&self) -> Option<Result<&'data str, Utf8Error>> {
self.data?;
Some(std::str::from_utf8(self.data.unwrap()))
}
/// Writes the LV to a raw buffer. Please note that the first byte will contain the length
/// of the value, but the values may not exceed a length of [u8::MAX].
pub fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {