better names
All checks were successful
Rust/spacepackets/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2022-09-13 10:28:20 +02:00
parent 7da7e5329c
commit 795abc57fa
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 9 additions and 8 deletions

View File

@ -17,9 +17,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Changed ## Changed
- Better names for generic error enumerations: `PacketError` renamed to `ByteConversionError` - Better names for generic error enumerations: `PacketError` renamed to `ByteConversionError`
- `ssc` abbreviations fully replaced by better name `seq_count` - CCSDS module: `ssc` abbreviations fully replaced by better name `seq_count`
- Time module: `CcsdsTimeProvider::date_time` now has `Option<DateTime<Utc>>` as - Time module: `CcsdsTimeProvider::date_time` now has `Option<DateTime<Utc>>` as
a returnvalue instead of `DateTime<Utc>` a returnvalue instead of `DateTime<Utc>`
- `PusTc` and `PusTm`: `new_from_raw_slice` renamed to simpler `from_bytes`
# [v0.1.0] 16.08.2022 # [v0.1.0] 16.08.2022

View File

@ -26,7 +26,7 @@
//! println!("{:?}", &test_buf[0..size]); //! println!("{:?}", &test_buf[0..size]);
//! //!
//! // Deserialize from the raw byte representation //! // Deserialize from the raw byte representation
//! let pus_tc_deserialized = PusTc::new_from_raw_slice(&test_buf).expect("Deserialization failed"); //! let pus_tc_deserialized = PusTc::from_bytes(&test_buf).expect("Deserialization failed");
//! assert_eq!(pus_tc.service(), 17); //! assert_eq!(pus_tc.service(), 17);
//! assert_eq!(pus_tc.subservice(), 1); //! assert_eq!(pus_tc.subservice(), 1);
//! assert_eq!(pus_tc.apid(), 0x02); //! assert_eq!(pus_tc.apid(), 0x02);
@ -401,7 +401,7 @@ impl<'slice> PusTc<'slice> {
/// Create a [PusTc] instance from a raw slice. On success, it returns a tuple containing /// Create a [PusTc] instance from a raw slice. On success, it returns a tuple containing
/// the instance and the found byte length of the packet /// the instance and the found byte length of the packet
pub fn new_from_raw_slice(slice: &'slice [u8]) -> Result<(Self, usize), PusError> { pub fn from_bytes(slice: &'slice [u8]) -> Result<(Self, usize), PusError> {
let raw_data_len = slice.len(); let raw_data_len = slice.len();
if raw_data_len < PUS_TC_MIN_LEN_WITHOUT_APP_DATA { if raw_data_len < PUS_TC_MIN_LEN_WITHOUT_APP_DATA {
return Err(PusError::RawDataTooShort(raw_data_len)); return Err(PusError::RawDataTooShort(raw_data_len));
@ -522,7 +522,7 @@ mod tests {
.write_to_bytes(test_buf.as_mut_slice()) .write_to_bytes(test_buf.as_mut_slice())
.expect("Error writing TC to buffer"); .expect("Error writing TC to buffer");
assert_eq!(size, 13); assert_eq!(size, 13);
let (tc_from_raw, size) = PusTc::new_from_raw_slice(&test_buf) let (tc_from_raw, size) = PusTc::from_bytes(&test_buf)
.expect("Creating PUS TC struct from raw buffer failed"); .expect("Creating PUS TC struct from raw buffer failed");
assert_eq!(size, 13); assert_eq!(size, 13);
verify_test_tc(&tc_from_raw, false, 13); verify_test_tc(&tc_from_raw, false, 13);
@ -548,7 +548,7 @@ mod tests {
.write_to_bytes(test_buf.as_mut_slice()) .write_to_bytes(test_buf.as_mut_slice())
.expect("Error writing TC to buffer"); .expect("Error writing TC to buffer");
assert_eq!(size, 16); assert_eq!(size, 16);
let (tc_from_raw, size) = PusTc::new_from_raw_slice(&test_buf) let (tc_from_raw, size) = PusTc::from_bytes(&test_buf)
.expect("Creating PUS TC struct from raw buffer failed"); .expect("Creating PUS TC struct from raw buffer failed");
assert_eq!(size, 16); assert_eq!(size, 16);
verify_test_tc(&tc_from_raw, true, 16); verify_test_tc(&tc_from_raw, true, 16);
@ -579,7 +579,7 @@ mod tests {
.write_to_bytes(test_buf.as_mut_slice()) .write_to_bytes(test_buf.as_mut_slice())
.expect("Error writing TC to buffer"); .expect("Error writing TC to buffer");
test_buf[12] = 0; test_buf[12] = 0;
let res = PusTc::new_from_raw_slice(&test_buf); let res = PusTc::from_bytes(&test_buf);
assert!(res.is_err()); assert!(res.is_err());
let err = res.unwrap_err(); let err = res.unwrap_err();
assert!(matches!(err, PusError::IncorrectCrc { .. })); assert!(matches!(err, PusError::IncorrectCrc { .. }));

View File

@ -387,7 +387,7 @@ impl<'slice> PusTm<'slice> {
/// Create a [PusTm] instance from a raw slice. On success, it returns a tuple containing /// Create a [PusTm] instance from a raw slice. On success, it returns a tuple containing
/// the instance and the found byte length of the packet. The timestamp length needs to be /// the instance and the found byte length of the packet. The timestamp length needs to be
/// known beforehand. /// known beforehand.
pub fn new_from_raw_slice( pub fn from_bytes(
slice: &'slice [u8], slice: &'slice [u8],
timestamp_len: usize, timestamp_len: usize,
) -> Result<(Self, usize), PusError> { ) -> Result<(Self, usize), PusError> {
@ -541,7 +541,7 @@ mod tests {
.expect("Serialization failed"); .expect("Serialization failed");
assert_eq!(ser_len, 22); assert_eq!(ser_len, 22);
let (tm_deserialized, size) = let (tm_deserialized, size) =
PusTm::new_from_raw_slice(&buf, 7).expect("Deserialization failed"); PusTm::from_bytes(&buf, 7).expect("Deserialization failed");
assert_eq!(ser_len, size); assert_eq!(ser_len, size);
verify_ping_reply(&tm_deserialized, false, 22, dummy_time_stamp()); verify_ping_reply(&tm_deserialized, false, 22, dummy_time_stamp());
} }