diff --git a/satrs-core/Cargo.toml b/satrs-core/Cargo.toml index 29d4122..a9ab91b 100644 --- a/satrs-core/Cargo.toml +++ b/satrs-core/Cargo.toml @@ -61,10 +61,11 @@ default-features = false optional = true [dependencies.spacepackets] -# version = "0.6" -# path = "../spacepackets" +version = "0.7.0-beta.0" +# path = "../../spacepackets" git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" -rev = "62df510147b" +rev = "00fdfde015040d0a349444136f6b41f3e44e3a15" +# branch = "size-missmatch-struct-variant" default-features = false [dev-dependencies] diff --git a/satrs-core/src/events.rs b/satrs-core/src/events.rs index 4b4c0c9..20267bd 100644 --- a/satrs-core/src/events.rs +++ b/satrs-core/src/events.rs @@ -33,7 +33,7 @@ use core::marker::PhantomData; use delegate::delegate; use spacepackets::ecss::EcssEnumeration; use spacepackets::util::{ToBeBytes, UnsignedEnum}; -use spacepackets::{ByteConversionError, SizeMissmatch}; +use spacepackets::ByteConversionError; /// Using a type definition allows to change this to u64 in the future more easily pub type LargestEventRaw = u32; @@ -124,10 +124,10 @@ impl EventBase { width: usize, ) -> Result { if buf.len() < width { - return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::ToSliceTooSmall { found: buf.len(), expected: width, - })); + }); } buf.copy_from_slice(raw.to_be_bytes().as_ref()); Ok(raw.written_len()) @@ -783,9 +783,9 @@ mod tests { let err = HIGH_SEV_EVENT.write_to_be_bytes(&mut buf); assert!(err.is_err()); let err = err.unwrap_err(); - if let ByteConversionError::ToSliceTooSmall(missmatch) = err { - assert_eq!(missmatch.expected, 4); - assert_eq!(missmatch.found, 3); + if let ByteConversionError::ToSliceTooSmall { found, expected } = err { + assert_eq!(expected, 4); + assert_eq!(found, 3); } } @@ -795,9 +795,9 @@ mod tests { let err = HIGH_SEV_EVENT_SMALL.write_to_be_bytes(&mut buf); assert!(err.is_err()); let err = err.unwrap_err(); - if let ByteConversionError::ToSliceTooSmall(missmatch) = err { - assert_eq!(missmatch.expected, 2); - assert_eq!(missmatch.found, 1); + if let ByteConversionError::ToSliceTooSmall { found, expected } = err { + assert_eq!(expected, 2); + assert_eq!(found, 1); } } diff --git a/satrs-core/src/mode.rs b/satrs-core/src/mode.rs index 7746572..cdd8f8d 100644 --- a/satrs-core/src/mode.rs +++ b/satrs-core/src/mode.rs @@ -2,7 +2,7 @@ use crate::tmtc::TargetId; use core::mem::size_of; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use spacepackets::{ByteConversionError, SizeMissmatch}; +use spacepackets::ByteConversionError; #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -26,10 +26,10 @@ impl ModeAndSubmode { pub fn from_be_bytes(buf: &[u8]) -> Result { if buf.len() < 6 { - return Err(ByteConversionError::FromSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::FromSliceTooSmall { expected: 6, found: buf.len(), - })); + }); } Ok(Self { mode: u32::from_be_bytes(buf[0..4].try_into().unwrap()), diff --git a/satrs-core/src/params.rs b/satrs-core/src/params.rs index 9df929b..bc9cc48 100644 --- a/satrs-core/src/params.rs +++ b/satrs-core/src/params.rs @@ -55,7 +55,6 @@ use paste::paste; use spacepackets::ecss::{EcssEnumU16, EcssEnumU32, EcssEnumU64, EcssEnumU8}; use spacepackets::util::UnsignedEnum; use spacepackets::ByteConversionError; -use spacepackets::SizeMissmatch; #[cfg(feature = "alloc")] pub use alloc_mod::*; @@ -80,10 +79,10 @@ macro_rules! param_to_be_bytes_impl { fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result { let raw_len = self.raw_len(); if buf.len() < raw_len { - return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::ToSliceTooSmall { found: buf.len(), expected: raw_len, - })); + }); } buf[0..raw_len].copy_from_slice(&self.to_be_bytes()); Ok(raw_len) @@ -186,10 +185,10 @@ macro_rules! scalar_byte_conversions_impl { fn try_from(v: &[u8]) -> Result { if v.len() < size_of::<$ty>() { - return Err(ByteConversionError::FromSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::FromSliceTooSmall{ expected: size_of::<$ty>(), found: v.len() - })); + }); } Ok([<$ty:upper>]($ty::from_be_bytes(v[0..size_of::<$ty>()].try_into().unwrap()))) } @@ -225,10 +224,10 @@ macro_rules! pair_byte_conversions_impl { fn try_from(v: &[u8]) -> Result { if v.len() < 2 * size_of::<$ty>() { - return Err(ByteConversionError::FromSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::FromSliceTooSmall{ expected: 2 * size_of::<$ty>(), found: v.len() - })); + }); } Ok([<$ty:upper Pair>]( $ty::from_be_bytes(v[0..size_of::<$ty>()].try_into().unwrap()), @@ -269,10 +268,10 @@ macro_rules! triplet_to_be_bytes_impl { fn try_from(v: &[u8]) -> Result { if v.len() < 3 * size_of::<$ty>() { - return Err(ByteConversionError::FromSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::FromSliceTooSmall{ expected: 3 * size_of::<$ty>(), found: v.len() - })); + }); } Ok([<$ty:upper Triplet>]( $ty::from_be_bytes(v[0..size_of::<$ty>()].try_into().unwrap()), diff --git a/satrs-core/src/pus/event.rs b/satrs-core/src/pus/event.rs index 954c77d..165493d 100644 --- a/satrs-core/src/pus/event.rs +++ b/satrs-core/src/pus/event.rs @@ -425,12 +425,12 @@ mod tests { let err = reporter.event_info(sender, &time_stamp_empty, event, None); assert!(err.is_err()); let err = err.unwrap_err(); - if let EcssTmtcError::Pus(PusError::ByteConversion(ByteConversionError::ToSliceTooSmall( - missmatch, - ))) = err + if let EcssTmtcError::Pus(PusError::ByteConversion( + ByteConversionError::ToSliceTooSmall { found, expected }, + )) = err { - assert_eq!(missmatch.expected, 4); - assert_eq!(missmatch.found, expected_found_len); + assert_eq!(expected, 4); + assert_eq!(found, expected_found_len); } else { panic!("Unexpected error {:?}", err); } diff --git a/satrs-core/src/pus/mod.rs b/satrs-core/src/pus/mod.rs index 9f9107a..cc05a92 100644 --- a/satrs-core/src/pus/mod.rs +++ b/satrs-core/src/pus/mod.rs @@ -14,7 +14,7 @@ use std::error::Error; use spacepackets::ecss::tc::{PusTcCreator, PusTcReader}; use spacepackets::ecss::tm::PusTmCreator; use spacepackets::ecss::PusError; -use spacepackets::{ByteConversionError, SizeMissmatch, SpHeader}; +use spacepackets::{ByteConversionError, SpHeader}; pub mod event; pub mod event_man; @@ -735,10 +735,10 @@ pub mod std_mod { pub(crate) fn source_buffer_large_enough(cap: usize, len: usize) -> Result<(), EcssTmtcError> { if len > cap { return Err( - PusError::ByteConversion(ByteConversionError::ToSliceTooSmall(SizeMissmatch { + PusError::ByteConversion(ByteConversionError::ToSliceTooSmall { found: cap, expected: len, - })) + }) .into(), ); } diff --git a/satrs-core/src/pus/verification.rs b/satrs-core/src/pus/verification.rs index 9c1fda9..47c2689 100644 --- a/satrs-core/src/pus/verification.rs +++ b/satrs-core/src/pus/verification.rs @@ -1584,12 +1584,12 @@ mod tests { assert_eq!(err_with_token.1, tok); match err_with_token.0 { EcssTmtcError::Pus(PusError::ByteConversion(e)) => match e { - ByteConversionError::ToSliceTooSmall(missmatch) => { + ByteConversionError::ToSliceTooSmall { found, expected } => { assert_eq!( - missmatch.expected, + expected, fail_data.len() + RequestId::SIZE_AS_BYTES + fail_code.size() ); - assert_eq!(missmatch.found, b.rep().allowed_source_data_len()); + assert_eq!(found, b.rep().allowed_source_data_len()); } _ => { panic!("{}", format!("Unexpected error {:?}", e)) diff --git a/satrs-core/src/res_code.rs b/satrs-core/src/res_code.rs index 5b0c64e..2ef7a88 100644 --- a/satrs-core/src/res_code.rs +++ b/satrs-core/src/res_code.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use spacepackets::ecss::{EcssEnumU16, EcssEnumeration}; use spacepackets::util::UnsignedEnum; -use spacepackets::{ByteConversionError, SizeMissmatch}; +use spacepackets::ByteConversionError; #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -42,10 +42,10 @@ impl UnsignedEnum for ResultU16 { fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result { if buf.len() < 2 { - return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::ToSliceTooSmall { found: buf.len(), expected: 2, - })); + }); } buf[0] = self.group_id; buf[1] = self.unique_id; diff --git a/satrs-core/src/tmtc/ccsds_distrib.rs b/satrs-core/src/tmtc/ccsds_distrib.rs index 6392e80..58fb8c6 100644 --- a/satrs-core/src/tmtc/ccsds_distrib.rs +++ b/satrs-core/src/tmtc/ccsds_distrib.rs @@ -89,7 +89,7 @@ use crate::tmtc::{ReceivesCcsdsTc, ReceivesTcCore}; use alloc::boxed::Box; use core::fmt::{Display, Formatter}; use downcast_rs::Downcast; -use spacepackets::{ByteConversionError, CcsdsPacket, SizeMissmatch, SpHeader}; +use spacepackets::{ByteConversionError, CcsdsPacket, SpHeader}; #[cfg(feature = "std")] use std::error::Error; @@ -174,10 +174,10 @@ impl ReceivesTcCore for CcsdsDistributor { fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> { if tc_raw.len() < 7 { return Err(CcsdsError::ByteConversionError( - ByteConversionError::FromSliceTooSmall(SizeMissmatch { + ByteConversionError::FromSliceTooSmall { found: tc_raw.len(), expected: 7, - }), + }, )); } let (sp_header, _) = diff --git a/satrs-core/src/tmtc/mod.rs b/satrs-core/src/tmtc/mod.rs index 5d5f306..7237196 100644 --- a/satrs-core/src/tmtc/mod.rs +++ b/satrs-core/src/tmtc/mod.rs @@ -9,7 +9,7 @@ use downcast_rs::{impl_downcast, Downcast}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use spacepackets::{ByteConversionError, SizeMissmatch, SpHeader}; +use spacepackets::{ByteConversionError, SpHeader}; #[cfg(feature = "alloc")] pub mod ccsds_distrib; @@ -34,10 +34,10 @@ pub struct AddressableId { impl AddressableId { pub fn from_raw_be(buf: &[u8]) -> Result { if buf.len() < 8 { - return Err(ByteConversionError::FromSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::FromSliceTooSmall { found: buf.len(), expected: 8, - })); + }); } Ok(Self { target_id: u32::from_be_bytes(buf[0..4].try_into().unwrap()), @@ -47,10 +47,10 @@ impl AddressableId { pub fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result { if buf.len() < 8 { - return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch { + return Err(ByteConversionError::ToSliceTooSmall { found: buf.len(), expected: 8, - })); + }); } buf[0..4].copy_from_slice(&self.target_id.to_be_bytes()); buf[4..8].copy_from_slice(&self.unique_id.to_be_bytes());