From 20018131995e05bd8871ddd6cfc97ecebe2c2ffa Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 28 Feb 2024 15:05:23 +0100 Subject: [PATCH] this should be compatible to no_std --- satrs/src/params.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/satrs/src/params.rs b/satrs/src/params.rs index 90d7028..2937e9e 100644 --- a/satrs/src/params.rs +++ b/satrs/src/params.rs @@ -619,7 +619,7 @@ impl From<&str> for Params { } /// Please note while [WritableToBeBytes] is implemented for [Params], the default implementation -/// will not be able to process store parameters. +/// will not be able to process the [Params::Store] parameter variant. impl WritableToBeBytes for Params { fn raw_len(&self) -> usize { match self { @@ -640,13 +640,25 @@ impl WritableToBeBytes for Params { ParamsHeapless::EcssEnum(enumeration) => enumeration.write_to_be_bytes(buf), }, Params::Store(_) => Ok(0), + #[cfg(feature = "alloc")] Params::Vec(vec) => { - // TODO: size checks. + if buf.len() < vec.len() { + return Err(ByteConversionError::ToSliceTooSmall { + found: buf.len(), + expected: vec.len(), + }); + } buf[0..vec.len()].copy_from_slice(vec); Ok(vec.len()) } + #[cfg(feature = "alloc")] Params::String(string) => { - // TODO: size checks + if buf.len() < string.len() { + return Err(ByteConversionError::ToSliceTooSmall { + found: buf.len(), + expected: string.len(), + }); + } buf[0..string.len()].copy_from_slice(string.as_bytes()); Ok(string.len()) }