m_bus_parser/user_data/
variable_user_data.rsuse super::data_information::{self};
use super::{DataRecords, FixedDataHeader};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DataRecordError {
DataInformationError(data_information::DataInformationError),
InsufficientData,
}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum VariableUserDataError {
DataInformationError(DataRecordError),
}
impl From<DataRecordError> for VariableUserDataError {
fn from(error: DataRecordError) -> Self {
Self::DataInformationError(error)
}
}
impl<'a> From<&'a [u8]> for DataRecords<'a> {
fn from(data: &'a [u8]) -> Self {
DataRecords::new(data, None)
}
}
impl<'a> From<(&'a [u8], &'a FixedDataHeader)> for DataRecords<'a> {
fn from((data, fixed_data_header): (&'a [u8], &'a FixedDataHeader)) -> Self {
DataRecords::new(data, Some(fixed_data_header))
}
}
mod tests {
#[test]
fn test_parse_variable_data() {
use crate::user_data::DataRecords;
let data = &[0x03, 0x13, 0x15, 0x31, 0x00];
let _result = DataRecords::try_from(data.as_slice());
}
#[test]
fn test_parse_variable_data2() {
let _data = &[0x01, 0xFD, 0x1B, 0x00];
}
#[cfg(feature = "plaintext-before-extension")]
#[test]
fn test_parse_variable_data3() {
use crate::user_data::DataRecords;
let data = &[0x02, 0xFC, 0x03, 0x48, 0x52, 0x25, 0x74, 0x44, 0x0D];
let _data = DataRecords::try_from(data.as_slice());
}
#[cfg(not(feature = "plaintext-before-extension"))]
#[test]
fn test_parse_variable_data3() {
use crate::user_data::DataRecords;
let data = &[0x02, 0xFC, 0x74, 0x03, 0x48, 0x52, 0x25, 0x44, 0x0D];
let _data = DataRecords::try_from(data.as_slice());
}
const fn _test_parse_variable_data2() {
let _data = &[0xDA, 0x02, 0x3B, 0x13, 0x01];
}
const fn _test_parse_variable_data3() {
let _data = &[0x8B, 0x60, 0x04, 0x37, 0x18, 0x02];
}
}